/*
 * @Author: 0x9DEFA478
 * @Date: 2025-05-06 20:37:21
 * @LastEditTime: 2025-08-10 17:28:30
 * @LastEditors: 0x9DEFA478
 * @Description: 
 * 
 */
#include "H_StringFormat.h"
#include "stdio.h"




/**
 * 
 *       
 *           
 * binary32 "Single precision"     32Bit  | 1bit Sign | 8bit  Exponent 127   | 1Bit Implicit 23bit Mantissa  |
 * binary64 "Double precision"     64Bit  | 1bit Sign | 11bit Exponent 1023  | 1Bit Implicit 52bit Mantissa  |
 * binary80 "Extended precision"   80Bit  | 1bit Sign | 15bit Exponent 16383 | 1Bit Explicit 63bit Mantissa  |
 * binary128 "Quadruple precision" 128Bit | 1bit Sign | 15bit Exponent 16383 | 1Bit Implicit 112bit Mantissa |
 * 
 * 
 * 
 * 
 */

#define Float_Type_Positive                                       1
#define Float_Type_Nagative                                       2
#define Float_Type_InfinitePositive                               -1
#define Float_Type_InfiniteNagative                               -2
#define Float_Type_QuietNotANumber                                -3
#define Float_Type_SingalingNotANumber                            -4


#if vH_Config_PointerSize==8
typedef Huint32 H_StringFormat_BigIntegerItemType;
typedef Huint64 H_StringFormat_BigIntegerLongItemType;
#define H_StringFormat_BigIntegerDivisorExp                       9
#define H_StringFormat_BigIntegerDivisor                          1000000000
#else
typedef Huint16 H_StringFormat_BigIntegerItemType;
typedef Huint32 H_StringFormat_BigIntegerLongItemType;
#define H_StringFormat_BigIntegerDivisorExp                       4
#define H_StringFormat_BigIntegerDivisor                          10000
#endif

//用于计算浮点整数部分的除法器
typedef struct{
  int WordSize;
  union{
    H_StringFormat_BigIntegerItemType* Word;
    Hbyte* Byte;
  }Buffer;
}H_StringFormat_BigIntegerDivider;

static inline void BigIntegerDivider_InitBuffer(H_StringFormat_BigIntegerDivider* BigIntegerDivider,H_StringFormat_BigIntegerItemType* WordArray,int WordSize){
  BigIntegerDivider->Buffer.Word=WordArray;
  BigIntegerDivider->WordSize=WordSize;
}

static int BigIntegerDivider_ToString(H_StringFormat_BigIntegerDivider* BigIntegerDivider,Huint32 FirstPos){
  int r;
  H_StringFormat_BigIntegerItemType* Word;
  Hbyte* Byte;
  int ByteSize;

  r=0;

  Word=BigIntegerDivider->Buffer.Word;
  Byte=BigIntegerDivider->Buffer.Byte;
  ByteSize=BigIntegerDivider->WordSize*sizeof(H_StringFormat_BigIntegerItemType);

  //大整形除法 循环除以H_StringFormat_BigIntegerDivisor
  do{
    Huint32 WordIndex;
    H_StringFormat_BigIntegerLongItemType remainder;

    remainder=(H_StringFormat_BigIntegerLongItemType)0U;

    WordIndex=FirstPos+1U;//循环中i首先减1 这里进行补偿 以适应i>0U的循环条件
    while(WordIndex>0U){
      H_StringFormat_BigIntegerLongItemType dividend;
      H_StringFormat_BigIntegerLongItemType quotient;

      WordIndex--;

      dividend=Word[WordIndex];
      remainder=(remainder<<(sizeof(H_StringFormat_BigIntegerItemType)*8))+dividend;
      quotient=remainder/(H_StringFormat_BigIntegerLongItemType)H_StringFormat_BigIntegerDivisor;
      remainder=remainder-quotient*(H_StringFormat_BigIntegerLongItemType)H_StringFormat_BigIntegerDivisor;
      Word[WordIndex]=(H_StringFormat_BigIntegerItemType)quotient;
    }

    //需要先更新FirstPos位置 避免高位被字符串覆盖
    while((FirstPos>0U)&&(Word[FirstPos]==(H_StringFormat_BigIntegerItemType)0U)){
      FirstPos--;
    }

    //生成字符串
    for(int i=0;i<H_StringFormat_BigIntegerDivisorExp;i++){
      H_StringFormat_BigIntegerItemType quotient;
      int rem;
      
      quotient=remainder/((H_StringFormat_BigIntegerItemType)10U);
      rem=(int)(remainder-quotient*((H_StringFormat_BigIntegerItemType)10U));
      remainder=quotient;

      r++;
      Byte[ByteSize-r]='0'+rem;
    }
    
  }while((FirstPos!=0U)||(Word[0]!=(H_StringFormat_BigIntegerItemType)0U));

  //去除前导0
  while((r>0)&&(Byte[ByteSize-r]=='0')){
    r--;
  }

  return r;
}

//用于计算浮点小数部分的乘法器
typedef struct{
  int Last;
  int WordSize;
  H_StringFormat_BigIntegerItemType* Word;
}H_StringFormat_BigIntegerMultiplier;

static inline void BigIntegerMultiplier_InitBuffer(H_StringFormat_BigIntegerMultiplier* BigIntegerDivider,H_StringFormat_BigIntegerItemType* WordArray,int WordSize){
  BigIntegerDivider->Last=-1;
  BigIntegerDivider->Word=WordArray;
  BigIntegerDivider->WordSize=WordSize;
}

static int BigIntegerMultiplier_Multiply(H_StringFormat_BigIntegerMultiplier* BigIntegerMultiplier,H_StringFormat_BigIntegerItemType* Product){
  Huint32 Index;
  H_StringFormat_BigIntegerItemType* Word;
  Huint32 LastPos;
  H_StringFormat_BigIntegerLongItemType product;
  
  product=(H_StringFormat_BigIntegerLongItemType)0U;

  LastPos=BigIntegerMultiplier->Last;
  Word=BigIntegerMultiplier->Word;

  if((LastPos==0U)&&(Word[LastPos]==(H_StringFormat_BigIntegerItemType)0U)){
    return 0;
  }

  Index=LastPos+1U;
  while(Index>0){
    H_StringFormat_BigIntegerLongItemType multiplicator;
    
    Index--;

    multiplicator=Word[Index];
    product+=multiplicator*H_StringFormat_BigIntegerDivisor;
    Word[Index]=(H_StringFormat_BigIntegerItemType)product;
    product>>=sizeof(H_StringFormat_BigIntegerItemType)*8;

  }

  *Product=(H_StringFormat_BigIntegerItemType)product;

  while((LastPos>0U)&&(Word[LastPos]==(H_StringFormat_BigIntegerItemType)0U)){
    LastPos--;
  }

  BigIntegerMultiplier->Last=LastPos;

  return 1;
}




#if H_StringFormat_f_UseSinglePrecision

static inline int floatDecode(float value,Huint32* Exponent,Huint32* Mantissa){
  int r;
  Hbyte* valueptr;

  r=0;

  valueptr=(Hbyte*)&value;

#if vH_Config_IsBigend
  if((valueptr[0]&0x80U)!=0U){
    r=1;
  }

  *Exponent=(Huint32)(((valueptr[0]<<1)|(valueptr[1]>>7))&0xFFU);
  *Mantissa=(
    ((Huint32)valueptr[3])
    |(((Huint32)valueptr[2])<<8)
    |(((Huint32)valueptr[1])<<16)
  )&((Huint32)0x007FFFFFU);
#else
  if((valueptr[3]&0x80U)!=0U){
    r=1;
  }

  *Exponent=(Huint32)(((valueptr[3]<<1)|(valueptr[2]>>7))&0xFFU);
  *Mantissa=(
    ((Huint32)valueptr[0])
    |(((Huint32)valueptr[1])<<8)
    |(((Huint32)valueptr[2])<<16)
  )&((Huint32)0x007FFFFFU);
#endif

  return r;
}

static inline int floatType(int Sign,Huint32 Exponent,Huint32 Mantissa){

  if(Exponent==((Huint32)0xFFU)){
    //inf or nan
    if(Mantissa==((Huint32)0x0U)){
      //inf
      if(Sign==0){
        return Float_Type_Positive;
      }
      return Float_Type_Nagative;
    }else{
      //nan
      if((Mantissa&(((Huint32)1U)<<(23-1)))==((Huint32)0U)){
        return Float_Type_SingalingNotANumber;
      }
      return Float_Type_QuietNotANumber;
    }
  }

  if(Sign==0){
    return Float_Type_Positive;
  }
  return Float_Type_Nagative;
}

/**
 * 二进制需要字节数(127+7)/8=16
 * 十进制字符字节数3.4*10^38 => 39
 * 进行除法生成商时 十进制字符增长的速度比二进制缩短的速度快, 缓冲区需要预留一些长度 H_StringFormat_BigIntegerDivider_ByteCountPadding
 * 并且二进制消耗完成与十进制完全生成是同时发生的
 * 字符每次增加H_StringFormat_BigIntegerDivisorExp字节, 还需要额外预留 
 *    (字符数%H_StringFormat_BigIntegerDivisorExp)?H_StringFormat_BigIntegerDivisorExp-(字符数%H_StringFormat_BigIntegerDivisorExp):0
 * 字节
 * 由于计算时以H_StringFormat_BigIntegerItemType为一个单位进行 至少预留sizeof(H_StringFormat_BigIntegerItemType)字节
 * 
 *   预留字节数=sizeof(H_StringFormat_BigIntegerItemType)+H_StringFormat_BigIntegerDivisorExp-1
 * 
 */
#define H_StringFormat_floatBigIntegerDivider_CharCount           39
#define H_StringFormat_floatBigIntegerDivider_PaddingCount        ((H_StringFormat_floatBigIntegerDivider_CharCount%H_StringFormat_BigIntegerDivisorExp)?H_StringFormat_BigIntegerDivisorExp-(H_StringFormat_floatBigIntegerDivider_CharCount%H_StringFormat_BigIntegerDivisorExp):0)
#define H_StringFormat_floatBigIntegerDivider_ByteCount           (H_StringFormat_floatBigIntegerDivider_CharCount+sizeof(H_StringFormat_BigIntegerItemType)+H_StringFormat_floatBigIntegerDivider_PaddingCount)
#define H_StringFormat_floatBigIntegerDivider_ItemCount           ((H_StringFormat_floatBigIntegerDivider_ByteCount+sizeof(H_StringFormat_BigIntegerItemType)-1)/sizeof(H_StringFormat_BigIntegerItemType))

static int floatBigIntegerDivider_ToString(H_StringFormat_BigIntegerDivider* BigIntegerDivider,Huint32 Exponent,Huint32 Mantissa){
  int WordSize;
  H_StringFormat_BigIntegerItemType* Word;
  int ByteSize;
  Huint32 FirstPos;

  WordSize=BigIntegerDivider->WordSize;
  Word=BigIntegerDivider->Buffer.Word;
  ByteSize=WordSize*sizeof(H_StringFormat_BigIntegerItemType);

  //清零大整形
  for(int i=0;i<WordSize;i++){
    Word[i]=(H_StringFormat_BigIntegerItemType)0U;
  }

  //小于1.0则直接返回0
  if(Exponent<0x7FU){
    BigIntegerDivider->Buffer.Byte[ByteSize-1]='0';
    return 1;
  }

  //整理尾数与幂
  Mantissa|=((Huint32)1U)<<23;
  if(Exponent<(23U+0x7FU)){//部分尾数为小数
    Mantissa>>=(23U+0x7FU)-Exponent;
    Exponent=0U;
  }else{//小数部分为0
    Exponent-=(23U+0x7FU);
  }
  
  //复制到大整形
  FirstPos=0U;
  while(Mantissa>0U){
    Huint32 ExponentOffset;
    Huint32 ExponentPos;
    Huint32 CopyCount;

    ExponentPos=Exponent/(sizeof(H_StringFormat_BigIntegerItemType)*8);
    ExponentOffset=Exponent-ExponentPos*(sizeof(H_StringFormat_BigIntegerItemType)*8);

    Word[ExponentPos]=((H_StringFormat_BigIntegerItemType)Mantissa)<<ExponentOffset;
    FirstPos=ExponentPos;

    CopyCount=(sizeof(H_StringFormat_BigIntegerItemType)*8)-ExponentOffset;

    if(CopyCount>=(sizeof(Mantissa)*8)){
      Mantissa=0U;
    }else{
      Mantissa>>=CopyCount;
    }
    Exponent+=CopyCount;
  }

  while((FirstPos>0U)&&(Word[FirstPos]==((H_StringFormat_BigIntegerItemType)0U))){
    FirstPos--;
  }

  return BigIntegerDivider_ToString(BigIntegerDivider,FirstPos);
}


/**
 * 二进制需要字节数(127-1+23+7)/8=19
 */
#define H_StringFormat_floatBigIntegerMultiplier_ByteCount        19
#define H_StringFormat_floatBigIntegerMultiplier_ItemCount        ((H_StringFormat_floatBigIntegerMultiplier_ByteCount+sizeof(H_StringFormat_BigIntegerItemType)-1)/sizeof(H_StringFormat_BigIntegerItemType))

static void floatBigIntegerMultiplier_Set(H_StringFormat_BigIntegerMultiplier* BigIntegerMultiplier,Huint32 Exponent,Huint32 Mantissa){
  H_StringFormat_BigIntegerItemType* Word;
  int WordSize;
  Huint32 LastPos;

  WordSize=BigIntegerMultiplier->WordSize;
  Word=BigIntegerMultiplier->Word;

  //清零大整形
  for(int i=0;i<WordSize;i++){
    Word[i]=(H_StringFormat_BigIntegerItemType)0U;
  }

  //大于2^23-1则直接返回 (小数部分为0)
  if(Exponent>(0x7FU+23U)){
    BigIntegerMultiplier->Last=0;
    return;
  }

  //整理尾数与幂
  if(Exponent==0U){//非规整化小数
    Mantissa<<=9;
    Exponent=0x7FU-1U;
  }else if(Exponent<0x7FU){//尾数全部为小数
    Mantissa|=((Huint32)1U)<<23;
    Mantissa<<=8;
    Exponent=0x7FU-1U-Exponent;
  }else{//部分尾数为整数
    Mantissa<<=9+(Exponent-0x7FU);
    Exponent=0U;
  }

  //复制到大整形
  LastPos=0U;
  while(Mantissa>0U){
    Huint32 ExponentOffset;
    Huint32 ExponentPos;
    Huint32 CopyCount;
    Hint32 RShift;

    ExponentPos=Exponent/(sizeof(H_StringFormat_BigIntegerItemType)*8);
    ExponentOffset=Exponent-ExponentPos*(sizeof(H_StringFormat_BigIntegerItemType)*8);

    RShift=(sizeof(Mantissa)-sizeof(H_StringFormat_BigIntegerItemType))*8+ExponentOffset;
    if(RShift<0){
      RShift=-RShift;
      Word[ExponentPos]=(H_StringFormat_BigIntegerItemType)(Mantissa<<RShift);
    }else{
      Word[ExponentPos]=(H_StringFormat_BigIntegerItemType)(Mantissa>>RShift);
    }
    LastPos=ExponentPos;

    CopyCount=(sizeof(H_StringFormat_BigIntegerItemType)*8)-ExponentOffset;

    if(CopyCount>=(sizeof(Mantissa)*8)){
      Mantissa=0U;
    }else{
      Mantissa<<=CopyCount;
    }
    Exponent+=CopyCount;
  }

  //去除前导0
  while((LastPos>0)&&(Word[LastPos]==(H_StringFormat_BigIntegerItemType)0U)){
    LastPos--;
  }

  BigIntegerMultiplier->Last=LastPos;

}

#endif




static inline int doubleDecode(double value,Huint32* Exponent,Huint64* Mantissa){
  int r;
  Hbyte* valueptr;

  r=0;

  valueptr=(Hbyte*)&value;

#if vH_Config_IsBigend
  if((valueptr[0]&0x80U)!=0U){
    r=1;
  }

  *Exponent=(Huint32)(((((Huint16)valueptr[0])<<4)|(((Huint16)valueptr[1])>>4))&0x7FFU);
  *Mantissa=(
    ((Huint64)valueptr[7])
    |(((Huint64)valueptr[6])<<8)
    |(((Huint64)valueptr[5])<<16)
    |(((Huint64)valueptr[4])<<24)
    |(((Huint64)valueptr[3])<<32)
    |(((Huint64)valueptr[2])<<40)
    |(((Huint64)valueptr[1])<<48)
  )&0x000FFFFFFFFFFFFFULL;
#else
  if((valueptr[7]&0x80U)!=0U){
    r=1;
  }

  *Exponent=(Huint32)(((((Huint16)valueptr[7])<<4)|(((Huint16)valueptr[6])>>4))&0x7FFU);
  *Mantissa=(
    ((Huint64)valueptr[0])
    |(((Huint64)valueptr[1])<<8)
    |(((Huint64)valueptr[2])<<16)
    |(((Huint64)valueptr[3])<<24)
    |(((Huint64)valueptr[4])<<32)
    |(((Huint64)valueptr[5])<<40)
    |(((Huint64)valueptr[6])<<48)
  )&0x000FFFFFFFFFFFFFULL;
#endif

  return r;
}

static inline int doubleType(int Sign,Huint32 Exponent,Huint64 Mantissa){
  
  if(Exponent==((Huint32)0x7FFU)){
    //inf or nan
    if(Mantissa==((Huint64)0x0U)){
      //inf
      if(Sign==0){
        return Float_Type_Positive;
      }
      return Float_Type_Nagative;
    }else{
      //nan
      if((Mantissa&(((Huint64)1U)<<(52-1)))==((Huint64)0U)){
        return Float_Type_SingalingNotANumber;
      }
      return Float_Type_QuietNotANumber;
    }
  }

  if(Sign==0){
    return Float_Type_Positive;
  }
  return Float_Type_Nagative;
}


/**
 * 二进制需要字节数(1023+7)/8=128
 * 十进制字符字节数1.768*10^308 => 309
 * 详细信息见H_StringFormat_floatBigIntegerDivider_ByteCount部分
 * 
 */
#define H_StringFormat_doubleBigIntegerDivider_CharCount          309
#define H_StringFormat_doubleBigIntegerDivider_PaddingCount       ((H_StringFormat_doubleBigIntegerDivider_CharCount%H_StringFormat_BigIntegerDivisorExp)?H_StringFormat_BigIntegerDivisorExp-(H_StringFormat_doubleBigIntegerDivider_CharCount%H_StringFormat_BigIntegerDivisorExp):0)
#define H_StringFormat_doubleBigIntegerDivider_ByteCount          (H_StringFormat_doubleBigIntegerDivider_CharCount+sizeof(H_StringFormat_BigIntegerItemType)+H_StringFormat_doubleBigIntegerDivider_PaddingCount)
#define H_StringFormat_doubleBigIntegerDivider_ItemCount          ((H_StringFormat_doubleBigIntegerDivider_ByteCount+sizeof(H_StringFormat_BigIntegerItemType)-1)/sizeof(H_StringFormat_BigIntegerItemType))

static int doubleBigIntegerDivider_ToString(H_StringFormat_BigIntegerDivider* BigIntegerDivider,Huint32 Exponent,Huint64 Mantissa){
  int WordSize;
  H_StringFormat_BigIntegerItemType* Word;
  int ByteSize;
  Huint32 FirstPos;

  WordSize=BigIntegerDivider->WordSize;
  Word=BigIntegerDivider->Buffer.Word;
  ByteSize=WordSize*sizeof(H_StringFormat_BigIntegerItemType);

  //清零大整形
  for(int i=0;i<WordSize;i++){
    Word[i]=(H_StringFormat_BigIntegerItemType)0U;
  }

  //小于1.0则直接返回0
  if(Exponent<0x3FFU){
    BigIntegerDivider->Buffer.Byte[ByteSize-1]='0';
    return 1;
  }

  //整理尾数与幂
  Mantissa|=((Huint64)1U)<<52;
  if(Exponent<(52U+0x3FFU)){//部分尾数为小数
    Mantissa>>=(52U+0x3FFU)-Exponent;
    Exponent=0U;
  }else{//小数部分为0
    Exponent-=(52U+0x3FFU);
  }
  
  //复制到大整形
  FirstPos=0U;
  while(Mantissa>0U){
    Huint32 ExponentOffset;
    Huint32 ExponentPos;
    Huint32 CopyCount;

    ExponentPos=Exponent/(sizeof(H_StringFormat_BigIntegerItemType)*8);
    ExponentOffset=Exponent-ExponentPos*(sizeof(H_StringFormat_BigIntegerItemType)*8);

    Word[ExponentPos]=((H_StringFormat_BigIntegerItemType)Mantissa)<<ExponentOffset;
    FirstPos=ExponentPos;

    CopyCount=(sizeof(H_StringFormat_BigIntegerItemType)*8)-ExponentOffset;

    if(CopyCount>=(sizeof(Mantissa)*8)){
      Mantissa=0U;
    }else{
      Mantissa>>=CopyCount;
    }
    Exponent+=CopyCount;
  }

  while((FirstPos>0U)&&(Word[FirstPos]==((H_StringFormat_BigIntegerItemType)0U))){
    FirstPos--;
  }

  return BigIntegerDivider_ToString(BigIntegerDivider,FirstPos);
}


/**
 * 二进制需要字节数(1023-1+52+7)/8=135
 */
#define H_StringFormat_doubleBigIntegerMultiplier_ByteCount       135
#define H_StringFormat_doubleBigIntegerMultiplier_ItemCount       ((H_StringFormat_doubleBigIntegerMultiplier_ByteCount+sizeof(H_StringFormat_BigIntegerItemType)-1)/sizeof(H_StringFormat_BigIntegerItemType))

static void doubleBigIntegerMultiplier_Set(H_StringFormat_BigIntegerMultiplier* BigIntegerMultiplier,Huint32 Exponent,Huint64 Mantissa){
  H_StringFormat_BigIntegerItemType* Word;
  int WordSize;
  Huint32 LastPos;

  WordSize=BigIntegerMultiplier->WordSize;
  Word=BigIntegerMultiplier->Word;

  //清零大整形
  for(int i=0;i<WordSize;i++){
    Word[i]=(H_StringFormat_BigIntegerItemType)0U;
  }

  //大于2^52-1则直接返回 (小数部分为0)
  if(Exponent>(0x3FFU+52U)){
    BigIntegerMultiplier->Last=0;
    return;
  }

  //整理尾数与幂
  if(Exponent==0U){//非规整化小数
    Mantissa<<=12;
    Exponent=0x3FFU-1U;
  }else if(Exponent<0x3FFU){//尾数全部为小数
    Mantissa|=((Huint64)1U)<<52;
    Mantissa<<=11;
    Exponent=0x3FFU-1U-Exponent;
  }else{//部分尾数为整数
    Mantissa<<=12+(Exponent-0x3FFU);
    Exponent=0U;
  }

  //复制到大整形
  LastPos=0U;
  while(Mantissa>0U){
    Huint32 ExponentOffset;
    Huint32 ExponentPos;
    Huint32 CopyCount;
    Hint32 RShift;

    ExponentPos=Exponent/(sizeof(H_StringFormat_BigIntegerItemType)*8);
    ExponentOffset=Exponent-ExponentPos*(sizeof(H_StringFormat_BigIntegerItemType)*8);

    RShift=(sizeof(Mantissa)-sizeof(H_StringFormat_BigIntegerItemType))*8+ExponentOffset;
    if(RShift<0){
      RShift=-RShift;
      Word[ExponentPos]=(H_StringFormat_BigIntegerItemType)(Mantissa<<RShift);
    }else{
      Word[ExponentPos]=(H_StringFormat_BigIntegerItemType)(Mantissa>>RShift);
    }
    LastPos=ExponentPos;

    CopyCount=(sizeof(H_StringFormat_BigIntegerItemType)*8)-ExponentOffset;

    if(CopyCount>=(sizeof(Mantissa)*8)){
      Mantissa=0ULL;
    }else{
      Mantissa<<=CopyCount;
    }
    Exponent+=CopyCount;
  }

  //去除前导0
  while((LastPos>0)&&(Word[LastPos]==(H_StringFormat_BigIntegerItemType)0U)){
    LastPos--;
  }

  BigIntegerMultiplier->Last=LastPos;

}




#if H_StringFormat_Support_Lf_Type==H_StringFormat_Support_Lf_Type_Binary80

static inline int longdoubleDecode(long double value,Huint64* Exponent,Huint64* MantissaArray){
  int r;
  Hbyte* valueptr;

  r=0;

  valueptr=(Hbyte*)&value;

#if vH_Config_IsBigend
  if((valueptr[0]&0x80U)!=0U){
    r=1;
  }

  *Exponent=(Huint64)(((((Huint16)valueptr[0])<<8)|((Huint16)valueptr[1]))&0x7FFFU);
  MantissaArray[0]=
    ((Huint64)valueptr[9])
    |(((Huint64)valueptr[8])<<8)
    |(((Huint64)valueptr[7])<<16)
    |(((Huint64)valueptr[6])<<24)
    |(((Huint64)valueptr[5])<<32)
    |(((Huint64)valueptr[4])<<40)
    |(((Huint64)valueptr[3])<<48)
    |(((Huint64)valueptr[2])<<56);
  MantissaArray[1]=0ULL;
#else
  if((valueptr[9]&0x80U)!=0U){
    r=1;
  }

  *Exponent=(Huint64)(((((Huint16)valueptr[9])<<8)|((Huint16)valueptr[8]))&0x7FFFU);
  MantissaArray[0]=
    ((Huint64)valueptr[0])
    |(((Huint64)valueptr[1])<<8)
    |(((Huint64)valueptr[2])<<16)
    |(((Huint64)valueptr[3])<<24)
    |(((Huint64)valueptr[4])<<32)
    |(((Huint64)valueptr[5])<<40)
    |(((Huint64)valueptr[6])<<48)
    |(((Huint64)valueptr[7])<<56);
  MantissaArray[1]=0ULL;
#endif

  return r;
}

#define longdouble_MantissaSize                                   64
#define longdouble_ExponentOffset                                 16383
#define longdouble_ImplicitFirstBit                               0

static inline int longdoubleType(int Sign,Huint32 Exponent,const Huint64* Mantissa){
  
  if(Exponent==((Huint32)0x7FFFU)){
    //inf or nan
    if(Mantissa[0]==((Huint64)0x0U)){
      //inf
      if(Sign==0){
        return Float_Type_Positive;
      }
      return Float_Type_Nagative;
    }else{
      //nan
      if((Mantissa[0]&(((Huint64)1U)<<(64-1)))==((Huint64)0U)){
        return Float_Type_SingalingNotANumber;
      }
      return Float_Type_QuietNotANumber;
    }
  }

  if(Sign==0){
    return Float_Type_Positive;
  }
  return Float_Type_Nagative;
}


/**
 * 二进制需要字节数(16383+7)/8=2048
 * 十进制字符字节数1.1897*10^4932 => 4933
 * 详细信息见H_StringFormat_floatBigIntegerDivider_ByteCount部分
 * 
 */
#define H_StringFormat_longdoubleBigIntegerDivider_CharCount      4933
#define H_StringFormat_longdoubleBigIntegerDivider_PaddingCount   ((H_StringFormat_longdoubleBigIntegerDivider_CharCount%H_StringFormat_BigIntegerDivisorExp)?H_StringFormat_BigIntegerDivisorExp-(H_StringFormat_longdoubleBigIntegerDivider_CharCount%H_StringFormat_BigIntegerDivisorExp):0)
#define H_StringFormat_longdoubleBigIntegerDivider_ByteCount      (H_StringFormat_longdoubleBigIntegerDivider_CharCount+sizeof(H_StringFormat_BigIntegerItemType)+H_StringFormat_longdoubleBigIntegerDivider_PaddingCount)
#define H_StringFormat_longdoubleBigIntegerDivider_ItemCount      ((H_StringFormat_longdoubleBigIntegerDivider_ByteCount+sizeof(H_StringFormat_BigIntegerItemType)-1)/sizeof(H_StringFormat_BigIntegerItemType))

static int longdoubleBigIntegerDivider_ToString(H_StringFormat_BigIntegerDivider* BigIntegerDivider,Huint32 Exponent,const Huint64* MantissaArray){
  int WordSize;
  H_StringFormat_BigIntegerItemType* Word;
  int ByteSize;
  Huint32 FirstPos;
  Huint64 Mantissa;

  WordSize=BigIntegerDivider->WordSize;
  Word=BigIntegerDivider->Buffer.Word;
  ByteSize=WordSize*sizeof(H_StringFormat_BigIntegerItemType);

  //清零大整形
  for(int i=0;i<WordSize;i++){
    Word[i]=(H_StringFormat_BigIntegerItemType)0U;
  }

  Mantissa=MantissaArray[0];

  //小于1.0则直接返回0
  if(Exponent<0x3FFFU){
    BigIntegerDivider->Buffer.Byte[ByteSize-1]='0';
    return 1;
  }

  //整理尾数与幂
  if(Exponent<(63U+0x3FFFU)){//部分尾数为小数
    Mantissa>>=(63U+0x3FFFU)-Exponent;
    Exponent=0U;
  }else{//小数部分为0
    Exponent-=(63U+0x3FFFU);
  }
  
  //复制到大整形
  FirstPos=0U;
  while(Mantissa>0ULL){
    Huint32 ExponentOffset;
    Huint32 ExponentPos;
    Huint32 CopyCount;

    ExponentPos=Exponent/(sizeof(H_StringFormat_BigIntegerItemType)*8);
    ExponentOffset=Exponent-ExponentPos*(sizeof(H_StringFormat_BigIntegerItemType)*8);

    Word[ExponentPos]=((H_StringFormat_BigIntegerItemType)Mantissa)<<ExponentOffset;
    FirstPos=ExponentPos;

    CopyCount=(sizeof(H_StringFormat_BigIntegerItemType)*8)-ExponentOffset;

    if(CopyCount>=(sizeof(Mantissa)*8)){
      Mantissa=0ULL;
    }else{
      Mantissa>>=CopyCount;
    }
    Exponent+=CopyCount;
  }

  while((FirstPos>0U)&&(Word[FirstPos]==((H_StringFormat_BigIntegerItemType)0U))){
    FirstPos--;
  }

  return BigIntegerDivider_ToString(BigIntegerDivider,FirstPos);
}


/**
 * 二进制需要字节数(16383-1+63+7)/8=2056
 */
#define H_StringFormat_longdoubleBigIntegerMultiplier_ByteCount   2056
#define H_StringFormat_longdoubleBigIntegerMultiplier_ItemCount   ((H_StringFormat_longdoubleBigIntegerMultiplier_ByteCount+sizeof(H_StringFormat_BigIntegerItemType)-1)/sizeof(H_StringFormat_BigIntegerItemType))

static void longdoubleBigIntegerMultiplier_Set(H_StringFormat_BigIntegerMultiplier* BigIntegerMultiplier,Huint32 Exponent,const Huint64* MantissaArray){
  H_StringFormat_BigIntegerItemType* Word;
  int WordSize;
  Huint32 LastPos;
  Huint64 Mantissa;

  WordSize=BigIntegerMultiplier->WordSize;
  Word=BigIntegerMultiplier->Word;

  //清零大整形
  for(int i=0;i<WordSize;i++){
    Word[i]=(H_StringFormat_BigIntegerItemType)0U;
  }

  Mantissa=MantissaArray[0];

  //大于2^63-1则直接返回 (小数部分为0)
  if(Exponent>(0x3FFFU+63U)){
    BigIntegerMultiplier->Last=0;
    return;
  }

  //整理尾数与幂
  if(Exponent==0U){//非规整化小数
    Mantissa<<=1;
    Exponent=0x3FFFU-1U;
  }else if(Exponent<0x3FFFU){//尾数全部为小数
    Exponent=0x3FFFU-1U-Exponent;
  }else{//部分尾数为整数
    Mantissa<<=1+(Exponent-0x3FFFU);
    Exponent=0U;
  }

  //复制到大整形
  LastPos=0U;
  while(Mantissa>0ULL){
    Huint32 ExponentOffset;
    Huint32 ExponentPos;
    Huint32 CopyCount;
    Hint32 RShift;

    ExponentPos=Exponent/(sizeof(H_StringFormat_BigIntegerItemType)*8);
    ExponentOffset=Exponent-ExponentPos*(sizeof(H_StringFormat_BigIntegerItemType)*8);

    RShift=(sizeof(Mantissa)-sizeof(H_StringFormat_BigIntegerItemType))*8+ExponentOffset;
    if(RShift<0){
      RShift=-RShift;
      Word[ExponentPos]=(H_StringFormat_BigIntegerItemType)(Mantissa<<RShift);
    }else{
      Word[ExponentPos]=(H_StringFormat_BigIntegerItemType)(Mantissa>>RShift);
    }
    LastPos=ExponentPos;

    CopyCount=(sizeof(H_StringFormat_BigIntegerItemType)*8)-ExponentOffset;

    if(CopyCount>=(sizeof(Mantissa)*8)){
      Mantissa=0ULL;
    }else{
      Mantissa<<=CopyCount;
    }
    Exponent+=CopyCount;
  }

  //去除前导0
  while((LastPos>0)&&(Word[LastPos]==(H_StringFormat_BigIntegerItemType)0U)){
    LastPos--;
  }

  BigIntegerMultiplier->Last=LastPos;

}


#elif H_StringFormat_Support_Lf_Type==H_StringFormat_Support_Lf_Type_Binary128

static inline int longdoubleDecode(Hlongdouble value,Huint64* Exponent,Huint64* MantissaArray){
  int r;
  Hbyte* valueptr;

  r=0;

  valueptr=(Hbyte*)&value;

#if vH_Config_IsBigend
  if((valueptr[0]&0x80U)!=0U){
    r=1;
  }

  *Exponent=(Huint64)(((((Huint16)valueptr[0])<<8)|((Huint16)valueptr[1]))&0x7FFFU);
  MantissaArray[0]=
    ((Huint64)valueptr[15])
    |(((Huint64)valueptr[14])<<8)
    |(((Huint64)valueptr[13])<<16)
    |(((Huint64)valueptr[12])<<24)
    |(((Huint64)valueptr[11])<<32)
    |(((Huint64)valueptr[10])<<40)
    |(((Huint64)valueptr[9])<<48)
    |(((Huint64)valueptr[8])<<56);
  MantissaArray[1]=
    ((Huint64)valueptr[7])
    |(((Huint64)valueptr[6])<<8)
    |(((Huint64)valueptr[5])<<16)
    |(((Huint64)valueptr[4])<<24)
    |(((Huint64)valueptr[3])<<32)
    |(((Huint64)valueptr[2])<<40);
#else
  if((valueptr[15]&0x80U)!=0U){
    r=1;
  }

  *Exponent=(Huint64)(((((Huint16)valueptr[15])<<8)|((Huint16)valueptr[14]))&0x7FFFU);
  MantissaArray[0]=
    ((Huint64)valueptr[0])
    |(((Huint64)valueptr[1])<<8)
    |(((Huint64)valueptr[2])<<16)
    |(((Huint64)valueptr[3])<<24)
    |(((Huint64)valueptr[4])<<32)
    |(((Huint64)valueptr[5])<<40)
    |(((Huint64)valueptr[6])<<48)
    |(((Huint64)valueptr[7])<<56);
  MantissaArray[1]=
    ((Huint64)valueptr[8])
    |(((Huint64)valueptr[9])<<8)
    |(((Huint64)valueptr[10])<<16)
    |(((Huint64)valueptr[11])<<24)
    |(((Huint64)valueptr[12])<<32)
    |(((Huint64)valueptr[13])<<40);
#endif

  return r;
}

#define longdouble_MantissaSize                                   112
#define longdouble_ExponentOffset                                 16383
#define longdouble_ImplicitFirstBit                               1

static inline int longdoubleType(int Sign,Huint32 Exponent,const Huint64* Mantissa){
  
  if(Exponent==((Huint32)0x7FFFU)){
    //inf or nan
    if((Mantissa[0]==((Huint64)0x0U))&&(Mantissa[1]==((Huint64)0x0U))){
      //inf
      if(Sign==0){
        return Float_Type_Positive;
      }
      return Float_Type_Nagative;
    }else{
      //nan
      if((Mantissa[1]&(((Huint64)1U)<<(48-1)))==((Huint64)0U)){
        return Float_Type_SingalingNotANumber;
      }
      return Float_Type_QuietNotANumber;
    }
  }

  if(Sign==0){
    return Float_Type_Positive;
  }
  return Float_Type_Nagative;
}


/**
 * 二进制需要字节数(16383+7)/8=2048
 * 十进制字符字节数1.1897*10^4932 => 4933
 * 详细信息见H_StringFormat_floatBigIntegerDivider_ByteCount部分
 * 
 */
#define H_StringFormat_longdoubleBigIntegerDivider_CharCount      4933
#define H_StringFormat_longdoubleBigIntegerDivider_PaddingCount   ((H_StringFormat_longdoubleBigIntegerDivider_CharCount%H_StringFormat_BigIntegerDivisorExp)?H_StringFormat_BigIntegerDivisorExp-(H_StringFormat_longdoubleBigIntegerDivider_CharCount%H_StringFormat_BigIntegerDivisorExp):0)
#define H_StringFormat_longdoubleBigIntegerDivider_ByteCount      (H_StringFormat_longdoubleBigIntegerDivider_CharCount+sizeof(H_StringFormat_BigIntegerItemType)+H_StringFormat_longdoubleBigIntegerDivider_PaddingCount)
#define H_StringFormat_longdoubleBigIntegerDivider_ItemCount      ((H_StringFormat_longdoubleBigIntegerDivider_ByteCount+sizeof(H_StringFormat_BigIntegerItemType)-1)/sizeof(H_StringFormat_BigIntegerItemType))

static int longdoubleBigIntegerDivider_ToString(H_StringFormat_BigIntegerDivider* BigIntegerDivider,Huint32 Exponent,const Huint64* MantissaArray){
  int WordSize;
  H_StringFormat_BigIntegerItemType* Word;
  int ByteSize;
  Huint32 FirstPos;
  Huint64 Mantissa[2];
  Huint32 exponent;
  int MantissaIndex;

  WordSize=BigIntegerDivider->WordSize;
  Word=BigIntegerDivider->Buffer.Word;
  ByteSize=WordSize*sizeof(H_StringFormat_BigIntegerItemType);

  //清零大整形
  for(int i=0;i<WordSize;i++){
    Word[i]=(H_StringFormat_BigIntegerItemType)0U;
  }

  Mantissa[0]=MantissaArray[0];
  Mantissa[1]=MantissaArray[1];

  //小于1.0则直接返回0
  if(Exponent<0x3FFFU){
    BigIntegerDivider->Buffer.Byte[ByteSize-1]='0';
    return 1;
  }

  //整理尾数与幂
  Mantissa[1]|=((Huint64)1U)<<(112-64);
  if(Exponent<(112U+0x3FFFU)){//部分尾数为小数
    Huint32 RShift;

    RShift=(112U+0x3FFFU)-Exponent;
    Mantissa[0]=(Mantissa[0]>>RShift)|(Mantissa[1]<<(64-RShift));
    Mantissa[1]>>=RShift;
    Exponent=0U;
  }else{//小数部分为0
    Exponent-=(112U+0x3FFFU);
  }
  
  //复制到大整形
  FirstPos=0U;
  exponent=Exponent;
  MantissaIndex=0;
  while(MantissaIndex<2){
    if(Mantissa[MantissaIndex]>0ULL){
      Huint32 ExponentOffset;
      Huint32 ExponentPos;
      Huint32 CopyCount;

      ExponentPos=exponent/(sizeof(H_StringFormat_BigIntegerItemType)*8);
      ExponentOffset=exponent-ExponentPos*(sizeof(H_StringFormat_BigIntegerItemType)*8);

      Word[ExponentPos]|=((H_StringFormat_BigIntegerItemType)Mantissa[MantissaIndex])<<ExponentOffset;
      FirstPos=ExponentPos;

      CopyCount=(sizeof(H_StringFormat_BigIntegerItemType)*8)-ExponentOffset;

      if(CopyCount>=(sizeof(Mantissa[0])*8)){
        Mantissa[MantissaIndex]=0ULL;
      }else{
        Mantissa[MantissaIndex]>>=CopyCount;
      }
      exponent+=CopyCount;
    }else{
      MantissaIndex++;
      exponent=Exponent+(sizeof(Mantissa[0])*8)*MantissaIndex;
    }
  }

  while((FirstPos>0U)&&(Word[FirstPos]==((H_StringFormat_BigIntegerItemType)0U))){
    FirstPos--;
  }

  return BigIntegerDivider_ToString(BigIntegerDivider,FirstPos);
}


/**
 * 二进制需要字节数(16383-1+112+7)/8=2062
 */
#define H_StringFormat_longdoubleBigIntegerMultiplier_ByteCount   2062
#define H_StringFormat_longdoubleBigIntegerMultiplier_ItemCount   ((H_StringFormat_longdoubleBigIntegerMultiplier_ByteCount+sizeof(H_StringFormat_BigIntegerItemType)-1)/sizeof(H_StringFormat_BigIntegerItemType))

static void longdoubleBigIntegerMultiplier_Set(H_StringFormat_BigIntegerMultiplier* BigIntegerMultiplier,Huint32 Exponent,const Huint64* MantissaArray){
  H_StringFormat_BigIntegerItemType* Word;
  int WordSize;
  Huint32 LastPos;
  Huint64 Mantissa[2];
  Huint32 exponent;
  int MantissaIndex;

  WordSize=BigIntegerMultiplier->WordSize;
  Word=BigIntegerMultiplier->Word;

  //清零大整形
  for(int i=0;i<WordSize;i++){
    Word[i]=(H_StringFormat_BigIntegerItemType)0U;
  }

  Mantissa[0]=MantissaArray[0];
  Mantissa[1]=MantissaArray[1];

  //大于2^63-1则直接返回 (小数部分为0)
  if(Exponent>(0x3FFFU+63U)){
    BigIntegerMultiplier->Last=0;
    return;
  }

  //整理尾数与幂
  if(Exponent==0U){//非规整化小数
    Mantissa[1]=(Mantissa[1]<<16)|(Mantissa[0]>>(64-16));
    Mantissa[0]<<=16;
    Exponent=0x3FFFU-1U;
  }else if(Exponent<0x3FFFU){//尾数全部为小数
    Mantissa[1]|=((Huint64)1U)<<(112-64);
    Mantissa[1]=(Mantissa[1]<<15)|(Mantissa[0]>>(64-15));
    Mantissa[0]<<=15;
    Exponent=0x3FFFU-1U-Exponent;
  }else{//部分尾数为整数
    Huint32 LShift;

    LShift=16+(Exponent-0x3FFFU);
    Mantissa[1]=(Mantissa[1]<<LShift)|(Mantissa[0]>>(64-LShift));
    Mantissa[0]<<=LShift;
    Exponent=0U;
  }

  //复制到大整形
  LastPos=0U;
  exponent=Exponent+sizeof(Mantissa[0])*8*(2-1);
  MantissaIndex=0;
  while(MantissaIndex<2){
    if(Mantissa[MantissaIndex]>0ULL){
      Huint32 ExponentOffset;
      Huint32 ExponentPos;
      Huint32 CopyCount;
      Hint32 RShift;

      ExponentPos=exponent/(sizeof(H_StringFormat_BigIntegerItemType)*8);
      ExponentOffset=exponent-ExponentPos*(sizeof(H_StringFormat_BigIntegerItemType)*8);

      RShift=(sizeof(Mantissa[0])-sizeof(H_StringFormat_BigIntegerItemType))*8+ExponentOffset;
      if(RShift<0){
        RShift=-RShift;
        Word[ExponentPos]|=(H_StringFormat_BigIntegerItemType)(Mantissa[MantissaIndex]<<RShift);
      }else{
        Word[ExponentPos]|=(H_StringFormat_BigIntegerItemType)(Mantissa[MantissaIndex]>>RShift);
      }
      if(LastPos<ExponentPos)
      LastPos=ExponentPos; 

      CopyCount=(sizeof(H_StringFormat_BigIntegerItemType)*8)-ExponentOffset;

      if(CopyCount>=(sizeof(Mantissa[0])*8)){
        Mantissa[MantissaIndex]=0ULL;
      }else{
        Mantissa[MantissaIndex]<<=CopyCount;
      }
      exponent+=CopyCount;
    }else{
      MantissaIndex++;
      exponent=Exponent+(sizeof(Mantissa[0])*8)*(2-1-MantissaIndex);
    }
  }

  //去除前导0
  while((LastPos>0)&&(Word[LastPos]==(H_StringFormat_BigIntegerItemType)0U)){
    LastPos--;
  }

  BigIntegerMultiplier->Last=LastPos;

}


#endif


//================================================================




#define vH_StringFormat_Attribute_LeftAlign                       (1U<<0)
#define vH_StringFormat_Attribute_Sign                            (1U<<1)
#define vH_StringFormat_Attribute_Space                           (1U<<2)
#define vH_StringFormat_Attribute_Prefix                          (1U<<3)
#define vH_StringFormat_Attribute_PaddingZero                     (1U<<4)
#define vH_StringFormat_Attribute_Size_h                          (1U<<5)
#define vH_StringFormat_Attribute_Size_l                          (2U<<5)
#define vH_StringFormat_Attribute_Size_ll                         (3U<<5)
#define vH_StringFormat_Attribute_Size_L                          vH_StringFormat_Attribute_Size_ll
#define vH_StringFormat_Attribute_Size_Mask                       (3U<<5)



#define vH_StringFormat_Type_Uppercase                            0x20U
#define vH_StringFormat_Type_FlagMask                             0x40U
#define vH_StringFormat_Type_LengthMask                           0x80U

#define vH_StringFormat_Type_c                                    0x01U
#define vH_StringFormat_Type_C                                    (vH_StringFormat_Type_Uppercase|vH_StringFormat_Type_c)
#define vH_StringFormat_Type_s                                    0x02U
#define vH_StringFormat_Type_S                                    (vH_StringFormat_Type_Uppercase|vH_StringFormat_Type_s)
#define vH_StringFormat_Type_d                                    0x03U
#define vH_StringFormat_Type_D                                    (vH_StringFormat_Type_Uppercase|vH_StringFormat_Type_d)
#define vH_StringFormat_Type_u                                    0x04U
#define vH_StringFormat_Type_U                                    (vH_StringFormat_Type_Uppercase|vH_StringFormat_Type_u)
#define vH_StringFormat_Type_f                                    0x05U
#define vH_StringFormat_Type_F                                    (vH_StringFormat_Type_Uppercase|vH_StringFormat_Type_f)
#define vH_StringFormat_Type_e                                    0x06U
#define vH_StringFormat_Type_E                                    (vH_StringFormat_Type_Uppercase|vH_StringFormat_Type_e)
#define vH_StringFormat_Type_g                                    0x07U
#define vH_StringFormat_Type_G                                    (vH_StringFormat_Type_Uppercase|vH_StringFormat_Type_g)
#define vH_StringFormat_Type_o                                    0x08U
#define vH_StringFormat_Type_O                                    (vH_StringFormat_Type_Uppercase|vH_StringFormat_Type_o)
#define vH_StringFormat_Type_x                                    0x09U
#define vH_StringFormat_Type_X                                    (vH_StringFormat_Type_Uppercase|vH_StringFormat_Type_x)
#define vH_StringFormat_Type_a                                    0x0AU
#define vH_StringFormat_Type_A                                    (vH_StringFormat_Type_Uppercase|vH_StringFormat_Type_a)
#define vH_StringFormat_Type_p                                    0x0BU
#define vH_StringFormat_Type_P                                    (vH_StringFormat_Type_Uppercase|vH_StringFormat_Type_p)

#define vH_StringFormat_Type_Specifier_Mask                       0x0FU

#define vH_StringFormat_Type_Specifier_Min                        vH_StringFormat_Type_c
#define vH_StringFormat_Type_Specifier_Max                        vH_StringFormat_Type_p


static const Hbyte CharType[128]={
  [0]=0x00U,//0
  [1]=0x00U,//1
  [2]=0x00U,//2
  [3]=0x00U,//3
  [4]=0x00U,//4
  [5]=0x00U,//5
  [6]=0x00U,//6
  [7]=0x00U,//7
  [8]=0x00U,//8
  [9]=0x00U,//9

  [10]=0x00U,//10
  [12]=0x00U,//12
  [13]=0x00U,//13
  [14]=0x00U,//14
  [15]=0x00U,//15
  [16]=0x00U,//16
  [17]=0x00U,//17
  [18]=0x00U,//18
  [19]=0x00U,//19

  [20]=0x00U,//20
  [21]=0x00U,//21
  [22]=0x00U,//22
  [23]=0x00U,//23
  [24]=0x00U,//24
  [25]=0x00U,//25
  [26]=0x00U,//26
  [27]=0x00U,//27
  [28]=0x00U,//28
  [29]=0x00U,//29

  [30]=0x00U,//30
  [31]=0x00U,//31
  [' ']=vH_StringFormat_Type_FlagMask,//32
  ['!']=0x00U,//33
  ['"']=0x00U,//34
  ['#']=vH_StringFormat_Type_FlagMask,//35
  ['$']=0x00U,//36
  ['%']=0x00U,//37
  ['&']=0x00U,//38
  ['\'']=0x00U,//39

  ['(']=0x00U,//40
  [')']=0x00U,//41
  ['*']=0x00U,//42
  ['+']=vH_StringFormat_Type_FlagMask,//43
  [',']=0x00U,//44
  ['-']=vH_StringFormat_Type_FlagMask,//45
  ['.']=0x00U,//46
  ['/']=0x00U,//47
  ['0']=vH_StringFormat_Type_FlagMask,//48
  ['1']=0x00U,//49

  ['2']=0x00U,//50
  ['3']=0x00U,//51
  ['4']=0x00U,//52
  ['5']=0x00U,//53
  ['6']=0x00U,//54
  ['7']=0x00U,//55
  ['8']=0x00U,//56
  ['9']=0x00U,//57
  [':']=0x00U,//58
  [';']=0x00U,//59

  ['<']=0x00U,//60
  ['=']=0x00U,//61
  ['>']=0x00U,//62
  ['?']=0x00U,//63
  ['@']=0x00U,//64
  ['A']=vH_StringFormat_Type_A,//65
  ['B']=0x00U,//66
  ['C']=vH_StringFormat_Type_C,//67
  ['D']=vH_StringFormat_Type_D,//68
  ['E']=vH_StringFormat_Type_E,//69

  ['F']=vH_StringFormat_Type_F,//70
  ['G']=vH_StringFormat_Type_G,//71
  ['H']=0x00U,//72
  ['I']=0x00U,//73
  ['J']=0x00U,//74
  ['K']=0x00U,//75
  ['L']=vH_StringFormat_Type_LengthMask,//76
  ['M']=0x00U,//77
  ['N']=0x00U,//78
  ['O']=vH_StringFormat_Type_O,//79

  ['P']=vH_StringFormat_Type_P,//80
  ['Q']=0x00U,//81
  ['R']=0x00U,//82
  ['S']=vH_StringFormat_Type_S,
  ['T']=0x00U,//84
  ['U']=vH_StringFormat_Type_U,//85
  ['V']=0x00U,//86
  ['W']=0x00U,//87
  ['X']=vH_StringFormat_Type_X,//88
  ['Y']=0x00U,//89

  ['Z']=0x00U,//90
  ['[']=0x00U,//91
  ['\\']=0x00U,//92
  [']']=0x00U,//93
  ['^']=0x00U,//94
  ['_']=0x00U,//95
  ['`']=0x00U,//96
  ['a']=vH_StringFormat_Type_a,//97
  ['b']=0x00U,//98
  ['c']=vH_StringFormat_Type_c,//99

  ['d']=vH_StringFormat_Type_d,//100
  ['e']=vH_StringFormat_Type_e,//101
  ['f']=vH_StringFormat_Type_f,//102
  ['g']=vH_StringFormat_Type_g,//103
  ['h']=vH_StringFormat_Type_LengthMask,//104
  ['i']=0x00U,//105
  ['j']=0x00U,//106
  ['k']=0x00U,//107
  ['l']=vH_StringFormat_Type_LengthMask,//108
  ['m']=0x00U,//109

  ['n']=0x00U,//110
  ['o']=vH_StringFormat_Type_o,//111
  ['p']=vH_StringFormat_Type_p,//112
  ['q']=0x00U,//113
  ['r']=0x00U,//114
  ['s']=vH_StringFormat_Type_s,//115
  ['t']=0x00U,//116
  ['u']=vH_StringFormat_Type_u,//117
  ['v']=0x00U,//118
  ['w']=0x00U,//119

  ['x']=vH_StringFormat_Type_x,//120
  ['y']=0x00U,//121
  ['z']=0x00U,//122
  ['{']=0x00U,//123
  ['|']=0x00U,//124
  ['}']=0x00U,//125
  ['~']=0x00U,//126
  [127]=0x00U//127
};

typedef struct{
  Hbyte Attribute;
  int Width;
  int Precision;
}ParamToString_Param;

typedef Hsize (*ParamToString_Function_t)(H_StringFormat_CharOutput*,const ParamToString_Param*,va_list*);

static Hsize ParamToString_Function_c(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params);
static Hsize ParamToString_Function_s(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params);
static Hsize ParamToString_Function_d(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params);
static Hsize ParamToString_Function_u(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params);
static Hsize ParamToString_Function_f(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params);
static Hsize ParamToString_Function_e(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params);
static Hsize ParamToString_Function_g(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params);
static Hsize ParamToString_Function_o(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params);
static Hsize ParamToString_Function_x(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params);
static Hsize ParamToString_Function_a(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params);
static Hsize ParamToString_Function_p(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params);

static const ParamToString_Function_t ParamToString_FunctionList[]={
  [vH_StringFormat_Type_c]=ParamToString_Function_c,
  [vH_StringFormat_Type_s]=ParamToString_Function_s,
  [vH_StringFormat_Type_d]=ParamToString_Function_d,
  [vH_StringFormat_Type_u]=ParamToString_Function_u,
  [vH_StringFormat_Type_f]=ParamToString_Function_f,
  [vH_StringFormat_Type_e]=ParamToString_Function_e,
  [vH_StringFormat_Type_g]=ParamToString_Function_g,
  [vH_StringFormat_Type_o]=ParamToString_Function_o,
  [vH_StringFormat_Type_x]=ParamToString_Function_x,
  [vH_StringFormat_Type_a]=ParamToString_Function_a,
  [vH_StringFormat_Type_p]=ParamToString_Function_p
};

#define ParamToString_Function_C ParamToString_Function_c
#define ParamToString_Function_S ParamToString_Function_s
#define ParamToString_Function_D ParamToString_Function_d
#define ParamToString_Function_U ParamToString_Function_u
#define ParamToString_Function_F ParamToString_Function_f
static Hsize ParamToString_Function_E(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params);
static Hsize ParamToString_Function_G(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params);
#define ParamToString_Function_O ParamToString_Function_o
static Hsize ParamToString_Function_X(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params);
static Hsize ParamToString_Function_A(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params);
#define ParamToString_Function_P ParamToString_Function_p

static const ParamToString_Function_t ParamToString_Uppercase_FunctionList[]={
  [vH_StringFormat_Type_c]=ParamToString_Function_C,
  [vH_StringFormat_Type_s]=ParamToString_Function_S,
  [vH_StringFormat_Type_d]=ParamToString_Function_D,
  [vH_StringFormat_Type_u]=ParamToString_Function_U,
  [vH_StringFormat_Type_f]=ParamToString_Function_F,
  [vH_StringFormat_Type_e]=ParamToString_Function_E,
  [vH_StringFormat_Type_g]=ParamToString_Function_G,
  [vH_StringFormat_Type_o]=ParamToString_Function_O,
  [vH_StringFormat_Type_x]=ParamToString_Function_X,
  [vH_StringFormat_Type_a]=ParamToString_Function_A,
  [vH_StringFormat_Type_p]=ParamToString_Function_P
};




static Hsize OutSpecificTypeFloat(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,int Type){
  static const char* TypeName[]={
    [Float_Type_Positive+4]="Positive",
    [Float_Type_Nagative+4]="Nagative",
    [Float_Type_InfinitePositive+4]="+Inf",
    [Float_Type_InfiniteNagative+4]="-Inf",
    [Float_Type_QuietNotANumber+4]="QNAN",
    [Float_Type_SingalingNotANumber+4]="SNAN"
  };

  H_StringFormat_CharOutput_Callback_t Output;
  Hsize r;

  Hbyte Attribute;
  int Width;

  const char* text;
  
  Output=CharOutput->Output;
  r=0;

  text=TypeName[Type+4];

  Attribute=paramToString_Param->Attribute;
  Width=paramToString_Param->Width;

  Width-=4;

  if((Attribute&vH_StringFormat_Attribute_LeftAlign)==0U){
    while(Width>0){
      Width--;
      Output(CharOutput,' ');
      r++;
    }
  }

  for(int i=0;i<4;i++){
    Output(CharOutput,text[i]);
    r++;
  }

  while(Width>0){
    Width--;
    Output(CharOutput,' ');
    r++;
  }

  return r;
}

typedef struct{
  Hbyte Attribute;
  int Width;
  int Precision;
  int Sign;
}H_StringFormat_BigIntegerDivider_Output_Param;

static Hsize BigIntegerDivider_Output(H_StringFormat_CharOutput* CharOutput,const H_StringFormat_BigIntegerDivider_Output_Param* Param,const Hbyte* Byte,int Length){
  H_StringFormat_CharOutput_Callback_t Output;
  Hsize r;

  Hbyte Attribute;
  int Width;
  int Precision;

  Output=CharOutput->Output;
  r=0;

  Attribute=Param->Attribute;
  Width=Param->Width;
  Precision=Param->Precision;

  if((Attribute&vH_StringFormat_Attribute_LeftAlign)!=0U){//左对齐

    if(Param->Sign!=0){
      Output(CharOutput,'-');
      r+=1;
    }else if((Attribute&vH_StringFormat_Attribute_Sign)!=0U){
      Output(CharOutput,'+');
      r+=1;
    }else if((Attribute&vH_StringFormat_Attribute_Space)!=0U){
      Output(CharOutput,' ');
      r+=1;
    }

  }else{//右对齐
    char padding;
    int paddingLength;

    paddingLength=Width-Length-Precision;

    if(Param->Sign!=0){
      paddingLength-=1;
    }else if((Attribute&(vH_StringFormat_Attribute_Sign|vH_StringFormat_Attribute_Space))!=0U){
      paddingLength-=1;
    }

    if(Precision>0){
      paddingLength-=1;//小数点
    }

    padding='0';
    if((Attribute&vH_StringFormat_Attribute_PaddingZero)==0U){
      padding=' ';
      
      while(paddingLength>0){
        paddingLength--;
        Output(CharOutput,padding);
        r++;
      }
    }

    if(Param->Sign!=0){
      Output(CharOutput,'-');
      r+=1;
    }else if((Attribute&vH_StringFormat_Attribute_Sign)!=0U){
      Output(CharOutput,'+');
      r+=1;
    }else if((Attribute&vH_StringFormat_Attribute_Space)!=0U){
      Output(CharOutput,' ');
      r+=1;
    }

    while(paddingLength>0){
      paddingLength--;
      Output(CharOutput,padding);
      r++;
    }

  }

  {
    for(int i=0;i<Length;i++){
      Output(CharOutput,Byte[i]);
    }
    r+=Length;
  }

  return r;
}

typedef struct{
  Hbyte Attribute;
  int Width;
  int Precision;
  int Sign;
  int ExpLength;
  int IsOutDot;
  Hint32 Exp;
}H_StringFormat_BigIntegerDivider_Output_eE_Param;

static Hsize BigIntegerDivider_Output_eE(H_StringFormat_CharOutput* CharOutput,H_StringFormat_BigIntegerDivider_Output_eE_Param* Param,const Hbyte* Byte,int Length){
  H_StringFormat_CharOutput_Callback_t Output;
  Hsize r;

  Hbyte Attribute;
  int Width;
  int Precision;

  Output=CharOutput->Output;
  r=0;

  Attribute=Param->Attribute;
  Width=Param->Width;
  Precision=Param->Precision;

  if((Attribute&vH_StringFormat_Attribute_LeftAlign)!=0U){//左对齐

    if(Param->Sign!=0){
      Output(CharOutput,'-');
      r+=1;
    }else if((Attribute&vH_StringFormat_Attribute_Sign)!=0U){
      Output(CharOutput,'+');
      r+=1;
    }else if((Attribute&vH_StringFormat_Attribute_Space)!=0U){
      Output(CharOutput,' ');
      r+=1;
    }

  }else{//右对齐
    char padding;
    int paddingLength;

    paddingLength=Width-1-Precision-(1+1)-Param->ExpLength;//首位 小数位 e 符号位 指数位

    if(Param->Sign!=0){
      paddingLength-=1;
    }else if((Attribute&(vH_StringFormat_Attribute_Sign|vH_StringFormat_Attribute_Space))!=0U){
      paddingLength-=1;
    }

    if(Precision>0){
      paddingLength-=1;//小数点
    }

    padding='0';
    if((Attribute&vH_StringFormat_Attribute_PaddingZero)==0U){
      padding=' ';
      
      while(paddingLength>0){
        paddingLength--;
        Output(CharOutput,padding);
        r++;
      }
    }

    if(Param->Sign!=0){
      Output(CharOutput,'-');
      r+=1;
    }else if((Attribute&vH_StringFormat_Attribute_Sign)!=0U){
      Output(CharOutput,'+');
      r+=1;
    }else if((Attribute&vH_StringFormat_Attribute_Space)!=0U){
      Output(CharOutput,' ');
      r+=1;
    }

    while(paddingLength>0){
      paddingLength--;
      Output(CharOutput,padding);
      r++;
    }

  }

  if((Length>1)||(Byte[0]!='0')){
    
    Param->Exp=Length;//暂时让Exp偏大1 便于后续判断

    Output(CharOutput,Byte[0]);
    r++;
    Byte++;
    Length--;

    if(Precision>0){
      Param->IsOutDot=1;
      
      Output(CharOutput,'.');
      r++;

      if(Length>Precision){
        Length=Precision;
      }

      for(int i=0;i<Length;i++){
        Output(CharOutput,Byte[i]);
      }
      r+=Length;
      Precision-=Length;
    }
  }

  Param->Precision=Precision;

  return r;
}

static Hsize BigIntegerMultiplier_Output(H_StringFormat_CharOutput* CharOutput,int Precision,H_StringFormat_BigIntegerMultiplier* BigIntegerMultiplier){
  H_StringFormat_CharOutput_Callback_t Output;
  Hsize r;

  H_StringFormat_BigIntegerItemType Product;
  int precisionCount;

  Output=CharOutput->Output;
  r=0;

  Output(CharOutput,'.');
  r++;

  precisionCount=0;
  while((precisionCount<Precision)&&(BigIntegerMultiplier_Multiply(BigIntegerMultiplier,&Product)!=0)){
    char Buffer[H_StringFormat_BigIntegerDivisorExp];
    int size;

    for(int i=0;i<H_StringFormat_BigIntegerDivisorExp;i++){
      H_StringFormat_BigIntegerItemType item;

      item=Product;
      Product/=10ULL;
      item=item-(Product*(H_StringFormat_BigIntegerItemType)10U);

      Buffer[H_StringFormat_BigIntegerDivisorExp-1-i]='0'+(int)item;
    }

    size=Precision-precisionCount;
    if(size>H_StringFormat_BigIntegerDivisorExp){
      size=H_StringFormat_BigIntegerDivisorExp;
    }
    for(int i=0;i<size;i++){
      Output(CharOutput,Buffer[i]);
      r++;
    }
    precisionCount+=size;
  }

  while(precisionCount<Precision){
    Output(CharOutput,'0');
    r++;
    precisionCount++;
  }

  return r;
}

typedef struct{
  int Precision;
  int Zero;
  int IsOutDot;
  Hint32 Exp;
}H_StringFormat_BigIntegerMultiplier_Output_eE_Param;

static Hsize BigIntegerMultiplier_Output_eE(H_StringFormat_CharOutput* CharOutput,H_StringFormat_BigIntegerMultiplier_Output_eE_Param* Param,H_StringFormat_BigIntegerMultiplier* BigIntegerMultiplier){
  H_StringFormat_CharOutput_Callback_t Output;
  Hsize r;

  int Precision;
  Hint32 Exp;

  H_StringFormat_BigIntegerItemType Product;
  int precisionCount;
  Hint32 exp;

  Output=CharOutput->Output;
  r=0;

  Precision=Param->Precision;
  Exp=Param->Exp;

  if((Exp!=0)&&(Param->IsOutDot==0)){
    Output(CharOutput,'.');
    r++;
  }

  precisionCount=0;
  
  if(Param->Zero!=0){
    Output(CharOutput,'0');
    r++;
    if(Precision>0){
      Output(CharOutput,'.');
      r++;
    }
    goto lMantissaZero;
  }

  exp=0;
  while(((precisionCount<Precision)||(Exp==0))&&(BigIntegerMultiplier_Multiply(BigIntegerMultiplier,&Product)!=0)){
    char Buffer[H_StringFormat_BigIntegerDivisorExp];
    int size;

    for(int i=0;i<H_StringFormat_BigIntegerDivisorExp;i++){
      H_StringFormat_BigIntegerItemType item;

      item=Product;
      Product/=10ULL;
      item=item-(Product*(H_StringFormat_BigIntegerItemType)10U);

      Buffer[H_StringFormat_BigIntegerDivisorExp-1-i]='0'+(int)item;
    }

    size=Precision-precisionCount;
    if(size>H_StringFormat_BigIntegerDivisorExp){
      size=H_StringFormat_BigIntegerDivisorExp;
    }
    
    if(Exp==0){
      for(int i=0;i<H_StringFormat_BigIntegerDivisorExp;i++){
        exp--;
        if(Buffer[i]!='0'){
          Exp=exp;

          Output(CharOutput,Buffer[i]);
          r++;

          if(Precision>0){
            Output(CharOutput,'.');
            r++;

            i++;
            while((i<H_StringFormat_BigIntegerDivisorExp)&&(precisionCount<Precision)){

              Output(CharOutput,Buffer[i]);
              r++;

              i++;
              precisionCount++;
            }
          }

          break;
        }
      }
    }else if(precisionCount<Precision){
      for(int i=0;i<size;i++){
        Output(CharOutput,Buffer[i]);
        r++;
      }
      precisionCount+=size;
    }
  }

lMantissaZero:
  while(precisionCount<Precision){
    Output(CharOutput,'0');
    r++;
    precisionCount++;
  }

  Param->Exp=Exp;

  return r;
}

static Hsize OutputExp(H_StringFormat_CharOutput* CharOutput,int Exp,int ExpLength,char* Buffer){
  H_StringFormat_CharOutput_Callback_t Output;
  Hsize r;

  Output=CharOutput->Output;
  r=0;

  if(Exp<0){
    Output(CharOutput,'-');
    r++;
  }else{
    Output(CharOutput,'+');
    r++;
  }

  if(Exp<0){
    Exp=-Exp;
  }

  for(int i=0;i<ExpLength;i++){
    int item;

    item=Exp;
    Exp/=10;
    item=item-Exp*10;
    
    Buffer[(ExpLength-1)-i]='0'+item;
  }
  for(int i=0;i<ExpLength;i++){
    Output(CharOutput,Buffer[i]);
  }
  r+=ExpLength;

  return r;
}


 

static Hsize ParamToString_Function_String(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,const char* String){
  H_StringFormat_CharOutput_Callback_t Output;
  Hsize r;

  Hbyte Attribute;
  int Width;
  int Precision;

  int size;

  Output=CharOutput->Output;
  r=0;

  size=0;
  while(String[size]!='\0'){
    size++;
  }

  Attribute=paramToString_Param->Attribute;
  Width=paramToString_Param->Width;
  Precision=paramToString_Param->Precision;
  if((Precision>=0)&&(size>Precision)){
    size=Precision;
  }

  if((Attribute&vH_StringFormat_Attribute_LeftAlign)==0U){//右对齐
    int paddingLength;

    paddingLength=Width-size;
    
    while(paddingLength>0){
      paddingLength--;
      Output(CharOutput,' ');
      r++;
    }
    
  }

  for(int i=0;i<size;i++){
    Output(CharOutput,String[i]);
  }
  r+=size;

  while(r<Width){
    Output(CharOutput,' ');
    r++;
  }

  return r;
}

static Hsize ParamToString_Function_Hex(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,Huint64 val,int size,char base){
  H_StringFormat_CharOutput_Callback_t Output;
  Hsize r;

  Hbyte Attribute;
  int Width;
  int Precision;

  Output=CharOutput->Output;
  r=0;

  size*=2;
  while((size>1)&&((val&(0xFULL<<(size*4-4)))==0ULL)){
    size--;
  }

  Width=paramToString_Param->Width;

  if(size<(Precision=paramToString_Param->Precision)){
    size=Precision;
  }

  Attribute=paramToString_Param->Attribute;

  if((Attribute&vH_StringFormat_Attribute_LeftAlign)!=0U){

    if((Attribute&vH_StringFormat_Attribute_Prefix)!=0U){
      Output(CharOutput,'0');
      Output(CharOutput,base);
      r+=2;
    }

    //左对齐不需要判断Padding 0

  }else{//右对齐
    char padding;
    int paddingLength;

    paddingLength=Width-size;

    padding=' ';
    if((Attribute&vH_StringFormat_Attribute_PaddingZero)!=0U){
      padding='0';
    }

    if((Attribute&vH_StringFormat_Attribute_Prefix)!=0U){
      paddingLength-=2;

      if(padding==' '){
        while(paddingLength>0){
          paddingLength--;
          Output(CharOutput,padding);
          r++;
        }
      }

      Output(CharOutput,'0');
      Output(CharOutput,base);
      r+=2;

    }

    while(paddingLength>0){
      paddingLength--;
      Output(CharOutput,padding);
      r++;
    }
    
  }

  {
    int i=size;

    while(i>0){
      int item;

      i--;
      item=((int)(val>>(i*4)))&0xFU;

      if(item<0xAU){
        Output(CharOutput,'0'+item);
      }else{
        Output(CharOutput,base-('x'-'a'+0xA)+item);
      }
      r++;
    }
  }

  while(r<Width){
    Output(CharOutput,' ');
    r++;
  }
  
  return r;
}

static Hsize ParamToString_Function_Oct(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,Huint64 val,int size){
  H_StringFormat_CharOutput_Callback_t Output;
  Hsize r;

  Hbyte Attribute;
  int Width;
  int Precision;

  Output=CharOutput->Output;
  r=0;

  size=(size*8+2)/3;
  while((size>1)&&((val&(0x7ULL<<(size*3-3)))==0ULL)){
    size--;
  }

  Width=paramToString_Param->Width;

  if(size<(Precision=paramToString_Param->Precision)){
    size=Precision;
  }

  Attribute=paramToString_Param->Attribute;

  if((Attribute&vH_StringFormat_Attribute_LeftAlign)!=0U){

    if((Attribute&vH_StringFormat_Attribute_Prefix)!=0U){
      Output(CharOutput,'0');
      r+=1;
    }

    //左对齐不需要判断Padding 0

  }else{//右对齐
    char padding;
    int paddingLength;

    paddingLength=Width-size;

    padding=' ';
    if((Attribute&vH_StringFormat_Attribute_PaddingZero)!=0U){
      padding='0';
    }

    if((Attribute&vH_StringFormat_Attribute_Prefix)!=0U){
      paddingLength-=1;

      if(padding==' '){
        while(paddingLength>0){
          paddingLength--;
          Output(CharOutput,padding);
          r++;
        }
      }

      Output(CharOutput,'0');
      r+=1;

    }

    while(paddingLength>0){
      paddingLength--;
      Output(CharOutput,padding);
      r++;
    }
    
  }

  {
    int i=size;

    while(i>0){
      int item;

      i--;
      item=((int)(val>>(i*3)))&0x7U;

      Output(CharOutput,'0'+item);
      r++;
    }
  }

  while(r<Width){
    Output(CharOutput,' ');
    r++;
  }
  
  return r;
}

static Hsize ParamToString_Function_HexDouble(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,double val,char base){
  H_StringFormat_CharOutput_Callback_t Output;
  Hsize r;

  Hbyte Attribute;
  int Width;
  int Precision;
  
  int Sign;
  Huint32 Exponent;
  Huint64 Mantissa;
  Hint32 Exp;
  Hint32 Exp_abs;
  Hint32 Exp_ItemSize;
  
  Output=CharOutput->Output;
  r=0;

  Sign=doubleDecode(val,&Exponent,&Mantissa);

  {
    int Type;

    Type=doubleType(Sign,Exponent,Mantissa);

    if(Type<0){
      return OutSpecificTypeFloat(CharOutput,paramToString_Param,Type);
    }
  }

  Width=paramToString_Param->Width;
  Width-=2+1+1+1;// 0x 首位 p 与指数的正负号

  Precision=paramToString_Param->Precision;
  if(Precision<0){
    Precision=13;//默认13bit精度
  }
  
  if(Precision>0){
    Width-=1+Precision;//小数点与精度需要的宽度
  }

  Attribute=paramToString_Param->Attribute;


  //符号位
  if(Sign!=0){
    Width-=1;
  }else if((Attribute&(vH_StringFormat_Attribute_Sign|vH_StringFormat_Attribute_Space))!=0U){
    Width-=1;
  }

  if(Exponent==0U){
    if(Mantissa==0ULL){
      Exp=0;
    }else{
      Exp=-1023+1; 
    }
  }else{
    Exp=(Hint32)Exponent-1023;
  }

  Exp_abs=Exp;
  if(Exp_abs<0){
    Exp_abs=-Exp_abs;
  }

  if(Exp_abs>999){
    Exp_ItemSize=4;
  }else if(Exp_abs>99){
    Exp_ItemSize=3;
  }else if(Exp_abs>9){
    Exp_ItemSize=2;
  }else{
    Exp_ItemSize=1;
  }
  Width-=Exp_ItemSize;

  if((Attribute&vH_StringFormat_Attribute_LeftAlign)!=0U){

    if(Sign!=0){
      Output(CharOutput,'-');
      r+=1;
    }else if((Attribute&vH_StringFormat_Attribute_Sign)!=0U){
      Output(CharOutput,'+');
      r+=1;
    }else if((Attribute&vH_StringFormat_Attribute_Space)!=0U){
      Output(CharOutput,' ');
      r+=1;
    }

    Output(CharOutput,'0');
    Output(CharOutput,base);
    r+=2;

    //左对齐不需要判断Padding 0

  }else{
    char padding;

    padding=' ';
    if((Attribute&vH_StringFormat_Attribute_PaddingZero)!=0U){
      padding='0';
    }else{
      while(Width>0){
        Width--;
        Output(CharOutput,padding);
        r++;
      }
    }

    if(Sign!=0){
      Output(CharOutput,'-');
      r+=1;
    }else if((Attribute&vH_StringFormat_Attribute_Sign)!=0U){
      Output(CharOutput,'+');
      r+=1;
    }else if((Attribute&vH_StringFormat_Attribute_Space)!=0U){
      Output(CharOutput,' ');
      r+=1;
    }
    
    Output(CharOutput,'0');
    Output(CharOutput,base);
    r+=2;

    while(Width>0){
      Width--;
      Output(CharOutput,padding);
      r++;
    }
  }

  
  if(Exponent==0U){
    Output(CharOutput,'0');
  }else{
    Output(CharOutput,'1');
  }
  r++;
  
  if(Precision>0){
    Output(CharOutput,'.');

    for(int i=0;i<Precision;i++){
      Hbyte item;

      item=(Hbyte)(Mantissa>>(((13-1)-i)*4));
      item&=0xFU;
      
      if(item<0xAU){
        Output(CharOutput,'0'+item);
      }else{
        Output(CharOutput,base-('x'-'a'+0xA)+item);
      }
    }

    r+=Precision+1;
  }

  Output(CharOutput,base-('x'-'p'));
  if(Exp<0){
    Output(CharOutput,'-');
  }else{
    Output(CharOutput,'+');
  }
  r+=2;

  {
    Hbyte itemList[4];
    
    for(int i=0;i<Exp_ItemSize;i++){
      itemList[Exp_ItemSize-1-i]=Exp_abs%10;
      Exp_abs/=10;
    }

    for(int i=0;i<Exp_ItemSize;i++){
      Output(CharOutput,'0'+itemList[i]);
    }
    r+=Exp_ItemSize;
  }

  while(Width>0){
    Width--;
    Output(CharOutput,' ');
    r++;
  }

  return r;
}


#if H_StringFormat_Support_Lf_Type!=H_StringFormat_Support_Lf_Type_None

#define longdouble_MantissaSizeHexCount ((longdouble_MantissaSize+3)/4)

static Hsize ParamToString_Function_HexLongDouble(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,Hlongdouble val,char base){
  H_StringFormat_CharOutput_Callback_t Output;
  Hsize r;

  Hbyte Attribute;
  int Width;
  int Precision;
  
  int Sign;
  Huint64 Exponent;
  Huint64 Mantissa[2];
  Hint64 Exp;
  Hint64 Exp_abs;
  Hint64 Exp_ItemSize;
  
  Output=CharOutput->Output;
  r=0;

  Sign=longdoubleDecode(val,&Exponent,Mantissa);

  {
    int Type;

    Type=longdoubleType(Sign,(Huint32)Exponent,Mantissa);

    if(Type<0){
      return OutSpecificTypeFloat(CharOutput,paramToString_Param,Type);
    }
  }

  Width=paramToString_Param->Width;
  Width-=2+1+1+1;// 0x 首位 p 与指数的正负号

  Precision=paramToString_Param->Precision;
  if(Precision<0){
#if longdouble_ImplicitFirstBit
    Precision=longdouble_MantissaSizeHexCount+1;//默认精度
#else
    Precision=longdouble_MantissaSizeHexCount;//默认精度
#endif
  }
  
  if(Precision>0){
    Width-=1+Precision;//小数点与精度需要的宽度
  }

  Attribute=paramToString_Param->Attribute;


  //符号位
  if(Sign!=0){
    Width-=1;
  }else if((Attribute&(vH_StringFormat_Attribute_Sign|vH_StringFormat_Attribute_Space))!=0U){
    Width-=1;
  }

  if(Exponent==0U){
    if((Mantissa[0]==0ULL)&&(Mantissa[1]==0ULL)){
      Exp=0LL;
    }else{
      Exp=-longdouble_ExponentOffset+1LL; 
    }
  }else{
    Exp=Exponent-longdouble_ExponentOffset;
  }

// #if longdouble_ImplicitFirstBit==0
//   if(Exp!=0ULL){
//     Exp+=1ULL;
//   }
// #endif

#if longdouble_ImplicitFirstBit==0
  Mantissa[1]=(Mantissa[1]<<1)|(Mantissa[0]>>63);
  Mantissa[0]<<=1;
#endif

  Exp_abs=Exp;
  if(Exp_abs<0){
    Exp_abs=-Exp_abs;
  }


#if (longdouble_ExponentOffset+1)>999999
#error "需要修改代码适应更大的Exponent"
#endif
#if (longdouble_ExponentOffset+1)>99999
  if(Exp_abs>99999LL){
    Exp_ItemSize=6LL;
  }else 
#endif
#if (longdouble_ExponentOffset+1)>9999
  if(Exp_abs>9999LL){
    Exp_ItemSize=5LL;
  }else 
#endif
  if(Exp_abs>999LL){
    Exp_ItemSize=4LL;
  }else if(Exp_abs>99LL){
    Exp_ItemSize=3LL;
  }else if(Exp_abs>9LL){
    Exp_ItemSize=2LL;
  }else{
    Exp_ItemSize=1LL;
  }
  Width-=Exp_ItemSize;

  if((Attribute&vH_StringFormat_Attribute_LeftAlign)!=0U){

    if(Sign!=0){
      Output(CharOutput,'-');
      r+=1;
    }else if((Attribute&vH_StringFormat_Attribute_Sign)!=0U){
      Output(CharOutput,'+');
      r+=1;
    }else if((Attribute&vH_StringFormat_Attribute_Space)!=0U){
      Output(CharOutput,' ');
      r+=1;
    }

    Output(CharOutput,'0');
    Output(CharOutput,base);
    r+=2;

    //左对齐不需要判断Padding 0

  }else{
    char padding;

    padding=' ';
    if((Attribute&vH_StringFormat_Attribute_PaddingZero)!=0U){
      padding='0';
    }else{
      while(Width>0){
        Width--;
        Output(CharOutput,padding);
        r++;
      }
    }

    if(Sign!=0){
      Output(CharOutput,'-');
      r+=1;
    }else if((Attribute&vH_StringFormat_Attribute_Sign)!=0U){
      Output(CharOutput,'+');
      r+=1;
    }else if((Attribute&vH_StringFormat_Attribute_Space)!=0U){
      Output(CharOutput,' ');
      r+=1;
    }
    
    Output(CharOutput,'0');
    Output(CharOutput,base);
    r+=2;

    while(Width>0){
      Width--;
      Output(CharOutput,padding);
      r++;
    }
  }

#if longdouble_ImplicitFirstBit
  if(Exponent==0ULL){
    Output(CharOutput,'0');
  }else{
    Output(CharOutput,'1');
  }
#else

#if longdouble_MantissaSize>=64
  if((Mantissa[1]&(1ULL<<(longdouble_MantissaSize-64)))!=0ULL){
    Output(CharOutput,'1');
  }else{
    Output(CharOutput,'0');
  }
#else
  if((Mantissa[0]&(1ULL<<(longdouble_MantissaSize-1)))!=0ULL){
    Output(CharOutput,'1');
  }else{
    Output(CharOutput,'0');
  }
#endif

#endif
  r++;
  
  if(Precision>0){
    Output(CharOutput,'.');

    for(int i=0;i<Precision;i++){
      int Offset;
      Hbyte item;

      Offset=((longdouble_MantissaSizeHexCount-1)-i)*4;

#if longdouble_MantissaSize>64
      if(Offset>63){
        item=(Hbyte)(Mantissa[1]>>(Offset-64));
      }else
#endif
      {
        item=(Hbyte)(Mantissa[0]>>Offset);
      }

      item&=0xFU;
      
      if(item<0xAU){
        Output(CharOutput,'0'+item);
      }else{
        Output(CharOutput,base-('x'-'a'+0xA)+item);
      }
    }

    r+=Precision+1;
  }

  Output(CharOutput,base-('x'-'p'));
  if(Exp<0){
    Output(CharOutput,'-');
  }else{
    Output(CharOutput,'+');
  }
  r+=2;

  {
    Hbyte itemList[6];
    
    for(int i=0;i<Exp_ItemSize;i++){
      itemList[Exp_ItemSize-1-i]=Exp_abs%10;
      Exp_abs/=10;
    }

    for(int i=0;i<Exp_ItemSize;i++){
      Output(CharOutput,'0'+itemList[i]);
    }
    r+=Exp_ItemSize;
  }

  while(Width>0){
    Width--;
    Output(CharOutput,' ');
    r++;
  }

  return r;
}
#endif

#if H_StringFormat_f_UseSinglePrecision

static Hsize FloatToOutput(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,float val){
  H_StringFormat_CharOutput_Callback_t Output;
  Hsize r;

  int Width;
  int Precision;
  
  int Sign;
  Huint32 Exponent;
  Huint32 Mantissa;

  Output=CharOutput->Output;
  r=0;

  Width=paramToString_Param->Width;
  Precision=paramToString_Param->Precision;
  if(Precision<0){
    Precision=6;//默认6位精度
  }

  Sign=floatDecode(val,&Exponent,&Mantissa);

  {
    //可能占用很大的栈空间 放置到代码块中以尽早释放
    H_StringFormat_BigIntegerItemType WordArray[H_StringFormat_floatBigIntegerDivider_ItemCount];
    H_StringFormat_BigIntegerDivider BigIntegerDivider;
    H_StringFormat_BigIntegerDivider_Output_Param Param;
    int size;

    BigIntegerDivider_InitBuffer(&BigIntegerDivider,WordArray,sizeof(WordArray)/sizeof(WordArray[0]));
    size=floatBigIntegerDivider_ToString(&BigIntegerDivider,Exponent,Mantissa);

    Param.Attribute=paramToString_Param->Attribute;
    Param.Width=Width;
    Param.Precision=Precision;
    Param.Sign=Sign;
    r+=BigIntegerDivider_Output(CharOutput,&Param,&BigIntegerDivider.Buffer.Byte[sizeof(WordArray)-size],size);
    
  }

  if(Precision>0){
    H_StringFormat_BigIntegerItemType WordArray[H_StringFormat_floatBigIntegerMultiplier_ItemCount];
    H_StringFormat_BigIntegerMultiplier BigIntegerMultiplier;
    H_StringFormat_BigIntegerItemType Product;
    int precisionCount;

    BigIntegerMultiplier_InitBuffer(&BigIntegerMultiplier,WordArray,sizeof(WordArray)/sizeof(WordArray[0]));
    floatBigIntegerMultiplier_Set(&BigIntegerMultiplier,Exponent,Mantissa);

    Output(CharOutput,'.');
    r++;

    precisionCount=0;
    while((precisionCount<Precision)&&(BigIntegerMultiplier_Multiply(&BigIntegerMultiplier,&Product)!=0)){
      char Buffer[H_StringFormat_BigIntegerDivisorExp];
      int size;

      for(int i=0;i<H_StringFormat_BigIntegerDivisorExp;i++){
        H_StringFormat_BigIntegerItemType item;

        item=Product;
        Product/=10ULL;
        item=item-(Product*(H_StringFormat_BigIntegerItemType)10U);

        Buffer[H_StringFormat_BigIntegerDivisorExp-1-i]='0'+(int)item;
      }

      size=Precision-precisionCount;
      if(size>H_StringFormat_BigIntegerDivisorExp){
        size=H_StringFormat_BigIntegerDivisorExp;
      }
      for(int i=0;i<size;i++){
        Output(CharOutput,Buffer[i]);
        r++;
      }
      precisionCount+=size;
    }

    while(precisionCount<Precision){
      Output(CharOutput,'0');
      r++;
      precisionCount++;
    }
  }

  while(r<Width){
    Output(CharOutput,' ');
    r++;
  }
  
  return r;
}

static Hsize FloatToOutput_eE(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,float val,char base){
  H_StringFormat_CharOutput_Callback_t Output;
  Hsize r;

  int Width;
  int Precision;
  
  int Sign;
  Huint32 Exponent;
  Huint32 Mantissa;
  int IsOutDot;
  Hint32 Exp;

  Output=CharOutput->Output;
  r=0;

  Width=paramToString_Param->Width;
  Precision=paramToString_Param->Precision;
  if(Precision<0){
    Precision=6;//默认6位精度
  }
  IsOutDot=0;
  Exp=0;

  Sign=floatDecode(val,&Exponent,&Mantissa);

  {
    H_StringFormat_BigIntegerItemType WordArray[H_StringFormat_floatBigIntegerDivider_ItemCount];
    H_StringFormat_BigIntegerDivider BigIntegerDivider;
    H_StringFormat_BigIntegerDivider_Output_eE_Param Param;
    int size;

    BigIntegerDivider_InitBuffer(&BigIntegerDivider,WordArray,sizeof(WordArray)/sizeof(WordArray[0]));
    size=floatBigIntegerDivider_ToString(&BigIntegerDivider,Exponent,Mantissa);

    Param.Attribute=paramToString_Param->Attribute;
    Param.Width=Width;
    Param.Precision=Precision;
    Param.Sign=Sign;
    Param.ExpLength=2;
    Param.IsOutDot=IsOutDot;
    Param.Exp=Exp;
    r+=BigIntegerDivider_Output_eE(CharOutput,&Param,&BigIntegerDivider.Buffer.Byte[sizeof(WordArray)-size],size);
    Precision=Param.Precision;
    IsOutDot=Param.IsOutDot;
    Exp=Param.Exp;

  }

  if((Precision>0)||(Exp==0)){
    H_StringFormat_BigIntegerItemType WordArray[H_StringFormat_floatBigIntegerMultiplier_ItemCount];
    H_StringFormat_BigIntegerMultiplier BigIntegerMultiplier;
    H_StringFormat_BigIntegerMultiplier_Output_eE_Param Param;

    BigIntegerMultiplier_InitBuffer(&BigIntegerMultiplier,WordArray,sizeof(WordArray)/sizeof(WordArray[0]));
    floatBigIntegerMultiplier_Set(&BigIntegerMultiplier,Exponent,Mantissa);

    Param.Precision=Precision;
    Param.Zero=((Exponent==0U)&&(Mantissa==0U))?1:0;
    Param.IsOutDot=IsOutDot;
    Param.Exp=Exp;
    r+=BigIntegerMultiplier_Output_eE(CharOutput,&Param,&BigIntegerMultiplier);
    Exp=Param.Exp;

  }

  {
    char Buffer[2];

    Output(CharOutput,base);
    r++;

    if((Exponent==0U)&&(Mantissa==0U)){
      Exp=0;
    }else if(Exp>0){
      Exp--;//纠正偏大的exp
    }

    r+=OutputExp(CharOutput,Exp,2,Buffer);

  }

  while(r<Width){
    Output(CharOutput,' ');
    r++;
  }
  
  return r;
}

#endif



static Hsize DoubleToOutput(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,double val){
  H_StringFormat_CharOutput_Callback_t Output;
  Hsize r;

  int Width;
  int Precision;
  
  int Sign;
  Huint32 Exponent;
  Huint64 Mantissa;

  Output=CharOutput->Output;
  r=0;

  Width=paramToString_Param->Width;
  Precision=paramToString_Param->Precision;
  if(Precision<0){
    Precision=6;//默认6位精度
  }

  Sign=doubleDecode(val,&Exponent,&Mantissa);

  {
    //可能占用很大的栈空间 放置到代码块中以尽早释放
    H_StringFormat_BigIntegerItemType WordArray[H_StringFormat_doubleBigIntegerDivider_ItemCount];
    H_StringFormat_BigIntegerDivider BigIntegerDivider;
    H_StringFormat_BigIntegerDivider_Output_Param Param;
    int size;

    BigIntegerDivider_InitBuffer(&BigIntegerDivider,WordArray,sizeof(WordArray)/sizeof(WordArray[0]));
    size=doubleBigIntegerDivider_ToString(&BigIntegerDivider,Exponent,Mantissa);

    Param.Attribute=paramToString_Param->Attribute;
    Param.Width=Width;
    Param.Precision=Precision;
    Param.Sign=Sign;
    r+=BigIntegerDivider_Output(CharOutput,&Param,&BigIntegerDivider.Buffer.Byte[sizeof(WordArray)-size],size);

  }

  if(Precision>0){
    H_StringFormat_BigIntegerItemType WordArray[H_StringFormat_doubleBigIntegerMultiplier_ItemCount];
    H_StringFormat_BigIntegerMultiplier BigIntegerMultiplier;

    BigIntegerMultiplier_InitBuffer(&BigIntegerMultiplier,WordArray,sizeof(WordArray)/sizeof(WordArray[0]));
    doubleBigIntegerMultiplier_Set(&BigIntegerMultiplier,Exponent,Mantissa);

    r+=BigIntegerMultiplier_Output(CharOutput,Precision,&BigIntegerMultiplier);
    
  }

  while(r<Width){
    Output(CharOutput,' ');
    r++;
  }
  
  return r;
}

static Hsize DoubleToOutput_eE(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,double val,char base){
  H_StringFormat_CharOutput_Callback_t Output;
  Hsize r;

  int Width;
  int Precision;
  
  int Sign;
  Huint32 Exponent;
  Huint64 Mantissa;
  int ExpLength;
  int IsOutDot;
  Hint32 Exp;

  Output=CharOutput->Output;
  r=0;

  Width=paramToString_Param->Width;
  Precision=paramToString_Param->Precision;
  if(Precision<0){
    Precision=6;//默认6位精度
  }
  ExpLength=2;
  IsOutDot=0;
  Exp=0;

  Sign=doubleDecode(val,&Exponent,&Mantissa);

  {
    double val_abs;

    //1e100 为了防止因编译器实现不同导致的常量舍入差异
    static const union{
      double val;
      unsigned char data[8];
    }v1e100={
#if vH_Config_IsBigend
      .data={0x54,0xB2,0x49,0xAD,0x25,0x94,0xC3,0x7D}
#else
      .data={0x7D,0xC3,0x94,0x25,0xAD,0x49,0xB2,0x54}
#endif
    };

    //1e-99 为了防止因编译器实现不同导致的常量舍入差异
    static const union{
      double val;
      unsigned char data[8];
    }v1en99={
#if vH_Config_IsBigend
      .data={0x2B,0x61,0x7F,0x7D,0x4E,0xD8,0xC3,0x3E}
#else
      .data={0x3E,0xC3,0xD8,0x4E,0x7D,0x7F,0x61,0x2B}
#endif
    };

    val_abs=val;
    if(Sign!=0){
      val_abs=-val_abs;
    }

    if((val_abs>=v1e100.val)||(val_abs<v1en99.val)){
      ExpLength=3;
    }
  }

  {
    H_StringFormat_BigIntegerItemType WordArray[H_StringFormat_doubleBigIntegerDivider_ItemCount];
    H_StringFormat_BigIntegerDivider BigIntegerDivider;
    H_StringFormat_BigIntegerDivider_Output_eE_Param Param;
    int size;

    BigIntegerDivider_InitBuffer(&BigIntegerDivider,WordArray,sizeof(WordArray)/sizeof(WordArray[0]));
    size=doubleBigIntegerDivider_ToString(&BigIntegerDivider,Exponent,Mantissa);

    Param.Attribute=paramToString_Param->Attribute;
    Param.Width=Width;
    Param.Precision=Precision;
    Param.Sign=Sign;
    Param.ExpLength=ExpLength;
    Param.IsOutDot=IsOutDot;
    Param.Exp=Exp;
    r+=BigIntegerDivider_Output_eE(CharOutput,&Param,&BigIntegerDivider.Buffer.Byte[sizeof(WordArray)-size],size);
    Precision=Param.Precision;
    IsOutDot=Param.IsOutDot;
    Exp=Param.Exp;

  }

  if((Precision>0)||(Exp==0)){
    H_StringFormat_BigIntegerItemType WordArray[H_StringFormat_doubleBigIntegerMultiplier_ItemCount];
    H_StringFormat_BigIntegerMultiplier BigIntegerMultiplier;
    H_StringFormat_BigIntegerMultiplier_Output_eE_Param Param;

    BigIntegerMultiplier_InitBuffer(&BigIntegerMultiplier,WordArray,sizeof(WordArray)/sizeof(WordArray[0]));
    doubleBigIntegerMultiplier_Set(&BigIntegerMultiplier,Exponent,Mantissa);

    Param.Precision=Precision;
    Param.Zero=((Exponent==0U)&&(Mantissa==0ULL))?1:0;
    Param.IsOutDot=IsOutDot;
    Param.Exp=Exp;
    r+=BigIntegerMultiplier_Output_eE(CharOutput,&Param,&BigIntegerMultiplier);
    Exp=Param.Exp;

  }

  {
    char Buffer[3];

    Output(CharOutput,base);
    r++;

    if((Exponent==0U)&&(Mantissa==0ULL)){
      Exp=0;
    }else if(Exp>0){
      Exp--;//纠正偏大的exp
    }

    r+=OutputExp(CharOutput,Exp,ExpLength,Buffer);

  }

  while(r<Width){
    Output(CharOutput,' ');
    r++;
  }
  
  return r;
}


#if H_StringFormat_Support_Lf_Type!=H_StringFormat_Support_Lf_Type_None
static Hsize LongDoubleToOutput(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,Hlongdouble val){
  H_StringFormat_CharOutput_Callback_t Output;
  Hsize r;

  int Width;
  int Precision;
  
  int Sign;
  Huint64 Exponent;
  Huint64 MantissaArray[2];

  Output=CharOutput->Output;
  r=0;

  Width=paramToString_Param->Width;
  Precision=paramToString_Param->Precision;
  if(Precision<0){
    Precision=6;//默认6位精度
  }

  Sign=longdoubleDecode(val,&Exponent,MantissaArray);

  {
    //可能占用很大的栈空间 放置到代码块中以尽早释放
    H_StringFormat_BigIntegerItemType WordArray[H_StringFormat_longdoubleBigIntegerDivider_ItemCount];
    H_StringFormat_BigIntegerDivider BigIntegerDivider;
    H_StringFormat_BigIntegerDivider_Output_Param Param;
    int size;

    BigIntegerDivider_InitBuffer(&BigIntegerDivider,WordArray,sizeof(WordArray)/sizeof(WordArray[0]));
    size=longdoubleBigIntegerDivider_ToString(&BigIntegerDivider,Exponent,MantissaArray);

    Param.Attribute=paramToString_Param->Attribute;
    Param.Width=Width;
    Param.Precision=Precision;
    Param.Sign=Sign;
    r+=BigIntegerDivider_Output(CharOutput,&Param,&BigIntegerDivider.Buffer.Byte[sizeof(WordArray)-size],size);

  }

  if(Precision>0){
    H_StringFormat_BigIntegerItemType WordArray[H_StringFormat_longdoubleBigIntegerMultiplier_ItemCount];
    H_StringFormat_BigIntegerMultiplier BigIntegerMultiplier;

    BigIntegerMultiplier_InitBuffer(&BigIntegerMultiplier,WordArray,sizeof(WordArray)/sizeof(WordArray[0]));
    longdoubleBigIntegerMultiplier_Set(&BigIntegerMultiplier,Exponent,MantissaArray);

    r+=BigIntegerMultiplier_Output(CharOutput,Precision,&BigIntegerMultiplier);
    
  }

  while(r<Width){
    Output(CharOutput,' ');
    r++;
  }
  
  return r;
}

static Hsize LongDoubleToOutput_eE(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,Hlongdouble val,char base){
  H_StringFormat_CharOutput_Callback_t Output;
  Hsize r;

  int Width;
  int Precision;
  
  int Sign;
  Huint64 Exponent;
  Huint64 MantissaArray[2];
  int ExpLength;
  int IsOutDot;
  Hint32 Exp;

  Output=CharOutput->Output;
  r=0;

  Width=paramToString_Param->Width;
  Precision=paramToString_Param->Precision;
  if(Precision<0){
    Precision=6;//默认6位精度
  }
  ExpLength=2;
  IsOutDot=0;
  Exp=0;

  Sign=longdoubleDecode(val,&Exponent,MantissaArray);

  {

#if H_StringFormat_Support_Lf_Type==H_StringFormat_Support_Lf_Type_Binary80
    Hlongdouble val_abs;

    //1e100 为了防止因编译器实现不同导致的常量舍入差异
    static const union{
      Hlongdouble val;
      unsigned char data[10];
    }v1e100={
#if vH_Config_IsBigend
      .data={0x41,0x4B,0x92,0x4D,0x69,0x2C,0xA6,0x1B,0xE7,0x59}
#else
      .data={0x59,0xE7,0x1B,0xA6,0x2C,0x69,0x4D,0x92,0x4B,0x41}
#endif
    };

    //1e-99 为了防止因编译器实现不同导致的常量舍入差异
    static const union{
      Hlongdouble val;
      unsigned char data[10];
    }v1en99={
#if vH_Config_IsBigend
      .data={0x3E,0xB6,0x8B,0xFB,0xEA,0x76,0xC6,0x19,0xEF,0x37}
#else
      .data={0x37,0xEF,0x19,0xC6,0x76,0xEA,0xFB,0x8B,0xB6,0x3E}
#endif
    };

    //1e1000 为了防止因编译器实现不同导致的常量舍入差异
    static const union{
      Hlongdouble val;
      unsigned char data[10];
    }v1e1000={
#if vH_Config_IsBigend
      .data={0x4C,0xF8,0xF3,0x8D,0xB1,0xF9,0xDD,0x3D,0xAC,0x06}
#else
      .data={0x06,0xAC,0x3D,0xDD,0xF9,0xB1,0x8D,0xF3,0xF8,0x4C}
#endif
    };

    //1e-999 为了防止因编译器实现不同导致的常量舍入差异
    static const union{
      Hlongdouble val;
      unsigned char data[10];
    }v1en999={
#if vH_Config_IsBigend
      .data={0x33,0x08,0xA8,0x2D,0x35,0xEA,0xD2,0xC5,0x99,0x81}
#else
      .data={0x81,0x99,0xC5,0xD2,0xEA,0x35,0x2D,0xA8,0x08,0x33}
#endif
    };

#elif H_StringFormat_Support_Lf_Type==H_StringFormat_Support_Lf_Type_Binary128
    Hlongdouble val_abs;

    //1e100 为了防止因编译器实现不同导致的常量舍入差异
    static const union{
      Hlongdouble val;
      unsigned char data[16];
    }v1e100={
#if vH_Config_IsBigend
      .data={0x41,0x4B,0x24,0x9A,0xD2,0x59,0x4C,0x37,0xCE,0xB0,0xB2,0x78,0x4C,0x4C,0xE0,0xC0}
#else
      .data={0xC0,0xE0,0x4C,0x4C,0x78,0xB2,0xB0,0xCE,0x37,0x4C,0x59,0xD2,0x9A,0x24,0x4B,0x41}
#endif
    };

    //1e-99 为了防止因编译器实现不同导致的常量舍入差异
    static const union{
      Hlongdouble val;
      unsigned char data[16];
    }v1en99={
#if vH_Config_IsBigend
      .data={0x3E,0xB6,0x17,0xF7,0xD4,0xED,0x8C,0x33,0xDE,0x6C,0xAF,0xD6,0x9D,0xB6,0x78,0xAC}
#else
      .data={0xAC,0x78,0xB6,0x9D,0xD6,0xAF,0x6C,0xDE,0x33,0x8C,0xED,0xD4,0xF7,0x17,0xB6,0x3E}
#endif
    };

    //1e1000 为了防止因编译器实现不同导致的常量舍入差异
    static const union{
      Hlongdouble val;
      unsigned char data[16];
    }v1e1000={
#if vH_Config_IsBigend
      .data={0x4C,0xF8,0xE7,0x1B,0x63,0xF3,0xBA,0x7B,0x58,0x0A,0xF1,0xA5,0x2D,0x2A,0x73,0x7A}
#else
      .data={0x7A,0x73,0x2A,0x2D,0xA5,0xF1,0x0A,0x58,0x7B,0xBA,0xF3,0x63,0x1B,0xE7,0xF8,0x4C}
#endif
    };

    //1e-999 为了防止因编译器实现不同导致的常量舍入差异
    static const union{
      Hlongdouble val;
      unsigned char data[16];
    }v1en999={
#if vH_Config_IsBigend
      .data={0x33,0x08,0x50,0x5A,0x6B,0xD5,0xA5,0x8B,0x33,0x01,0xA8,0x2F,0xB1,0xB0,0x8A,0x73}
#else
      .data={0x73,0x8A,0xB0,0xB1,0x2F,0xA8,0x01,0x33,0x8B,0xA5,0xD5,0x6B,0x5A,0x50,0x08,0x33}
#endif
    };

#endif

    val_abs=val;
    if(Sign!=0){
      val_abs=-val_abs;
    }

    if((val_abs>=v1e1000.val)||(val_abs<v1en999.val)){
      ExpLength=4;
    }else if((val_abs>=v1e100.val)||(val_abs<v1en99.val)){
      ExpLength=3;
    }
  }

  {
    H_StringFormat_BigIntegerItemType WordArray[H_StringFormat_longdoubleBigIntegerDivider_ItemCount];
    H_StringFormat_BigIntegerDivider BigIntegerDivider;
    H_StringFormat_BigIntegerDivider_Output_eE_Param Param;
    int size;

    BigIntegerDivider_InitBuffer(&BigIntegerDivider,WordArray,sizeof(WordArray)/sizeof(WordArray[0]));
    size=longdoubleBigIntegerDivider_ToString(&BigIntegerDivider,Exponent,MantissaArray);

    Param.Attribute=paramToString_Param->Attribute;
    Param.Width=Width;
    Param.Precision=Precision;
    Param.Sign=Sign;
    Param.ExpLength=ExpLength;
    Param.IsOutDot=IsOutDot;
    Param.Exp=Exp;
    r+=BigIntegerDivider_Output_eE(CharOutput,&Param,&BigIntegerDivider.Buffer.Byte[sizeof(WordArray)-size],size);
    Precision=Param.Precision;
    IsOutDot=Param.IsOutDot;
    Exp=Param.Exp;

  }

  if((Precision>0)||(Exp==0)){
    H_StringFormat_BigIntegerItemType WordArray[H_StringFormat_longdoubleBigIntegerMultiplier_ItemCount];
    H_StringFormat_BigIntegerMultiplier BigIntegerMultiplier;
    H_StringFormat_BigIntegerMultiplier_Output_eE_Param Param;

    BigIntegerMultiplier_InitBuffer(&BigIntegerMultiplier,WordArray,sizeof(WordArray)/sizeof(WordArray[0]));
    longdoubleBigIntegerMultiplier_Set(&BigIntegerMultiplier,Exponent,MantissaArray);

    Param.Precision=Precision;
    Param.Zero=((Exponent==0ULL)&&(MantissaArray[0]==0ULL)&&(MantissaArray[1]==0ULL))?1:0;
    Param.IsOutDot=IsOutDot;
    Param.Exp=Exp;
    r+=BigIntegerMultiplier_Output_eE(CharOutput,&Param,&BigIntegerMultiplier);
    Exp=Param.Exp;

  }

  {
    char Buffer[4];

    Output(CharOutput,base);
    r++;

    if((Exponent==0ULL)&&(MantissaArray[0]==0ULL)&&(MantissaArray[1]==0ULL)){
      Exp=0;
    }else if(Exp>0){
      Exp--;//纠正偏大的exp
    }

    r+=OutputExp(CharOutput,Exp,ExpLength,Buffer);

  }

  while(r<Width){
    Output(CharOutput,' ');
    r++;
  }
  
  return r;
}
#endif


static Hsize ParamToString_Function_c(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params){
  H_StringFormat_CharOutput_Callback_t Output;
  int c;
  int Width;
  Hbyte Attribute;
  Hsize r;

  Output=CharOutput->Output;
  r=1;

  c=va_arg(*Params,int);


  Attribute=paramToString_Param->Attribute;

  if((Attribute&vH_StringFormat_Attribute_LeftAlign)!=0U){
    Output(CharOutput,(char)c);
  }

  Width=paramToString_Param->Width;
  while(Width>1){
    Width--;
    Output(CharOutput,' ');
    r++;
  }

  if((Attribute&vH_StringFormat_Attribute_LeftAlign)==0U){
    Output(CharOutput,(char)c);
  }

  return r;
}

static Hsize ParamToString_Function_s(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params){
  const char* s;

  s=va_arg(*Params,const char*);

  return ParamToString_Function_String(CharOutput,paramToString_Param,s);
}

static Hsize ParamToString_Function_d(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params){
  H_StringFormat_CharOutput_Callback_t Output;
  Hsize r;

  Hbyte Attribute;
  int Width;
  int Precision;

  int size;
  int Sign;
  Hint64 sval;
  Huint64 val;
  char Buffer[20];

  Output=CharOutput->Output;
  r=0;

  Attribute=paramToString_Param->Attribute;
  switch(Attribute&vH_StringFormat_Attribute_Size_Mask){
    case vH_StringFormat_Attribute_Size_h:
      {
        Hint16 val16;
        Huint16 valu16;
        valu16=(Huint16)va_arg(*Params,unsigned int);
        val16=(Hint16)valu16;

        sval=val16;
      }
      break;
    case vH_StringFormat_Attribute_Size_l:
      sval=va_arg(*Params,long int);
      break;
    case vH_StringFormat_Attribute_Size_ll:
      sval=va_arg(*Params,long long int);
      break;
    default:
      sval=va_arg(*Params,int);
      break;
  }

  if(sval<0){
    val=-sval;
    Sign=1;
  }else{
    val=sval;
    Sign=0;
  }

  size=0;
  if(val==0){
    Buffer[size]='0';
    size++;
  }else{
    while(val!=0ULL){
      Huint64 item;
  
      item=val;
      val/=10ULL;
      item=item-(val*10ULL);
  
      Buffer[size]='0'+(int)item;
      size++;
    }
  }

  Width=paramToString_Param->Width;

  if(size<(Precision=paramToString_Param->Precision)){
    for(int i=size;i<Precision;i++){
      Buffer[i]='0';
    }
    size=Precision;
  }

  if((Attribute&vH_StringFormat_Attribute_LeftAlign)!=0U){//左对齐

    if(Sign!=0){
      Output(CharOutput,'-');
      r+=1;
    }else if((Attribute&vH_StringFormat_Attribute_Sign)!=0U){
      Output(CharOutput,'+');
      r+=1;
    }else if((Attribute&vH_StringFormat_Attribute_Space)!=0U){
      Output(CharOutput,' ');
      r+=1;
    }

  }else{//右对齐
    char padding;
    int paddingLength;

    paddingLength=Width-size;
    
    if(Sign!=0){
      paddingLength-=1;
    }else if((Attribute&(vH_StringFormat_Attribute_Sign|vH_StringFormat_Attribute_Space))!=0U){
      paddingLength-=1;
    }
    
    padding='0';
    if((Attribute&vH_StringFormat_Attribute_PaddingZero)==0U){
      padding=' ';
      
      while(paddingLength>0){
        paddingLength--;
        Output(CharOutput,padding);
        r++;
      }
    }

    if(Sign!=0){
      Output(CharOutput,'-');
      r+=1;
    }else if((Attribute&vH_StringFormat_Attribute_Sign)!=0U){
      Output(CharOutput,'+');
      r+=1;
    }else if((Attribute&vH_StringFormat_Attribute_Space)!=0U){
      Output(CharOutput,' ');
      r+=1;
    }

    while(paddingLength>0){
      paddingLength--;
      Output(CharOutput,padding);
      r++;
    }
    
  }

  for(int i=0;i<size;i++){
    Output(CharOutput,Buffer[size-1-i]);
  }
  r+=size;

  while(r<Width){
    Output(CharOutput,' ');
    r++;
  }
  
  return r;
}

static Hsize ParamToString_Function_u(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params){
  H_StringFormat_CharOutput_Callback_t Output;
  Hsize r;

  Hbyte Attribute;
  int Width;
  int Precision;

  int size;
  Huint64 val;
  char Buffer[20];
  
  Output=CharOutput->Output;
  r=0;

  Attribute=paramToString_Param->Attribute;
  switch(Attribute&vH_StringFormat_Attribute_Size_Mask){
    case vH_StringFormat_Attribute_Size_h:
      val=va_arg(*Params,unsigned int);
      val&=0xFFFFULL;
      break;
    case vH_StringFormat_Attribute_Size_l:
      val=va_arg(*Params,unsigned long int);
      break;
    case vH_StringFormat_Attribute_Size_ll:
      val=va_arg(*Params,unsigned long long int);
      break;
    default:
      val=va_arg(*Params,unsigned int);
      break;
  }

  size=0;
  if(val==0){
    Buffer[size]='0';
    size++;
  }else{
    while(val!=0ULL){
      Huint64 item;
  
      item=val;
      val/=10ULL;
      item=item-(val*10ULL);
  
      Buffer[size]='0'+(int)item;
      size++;
    }
  }

  Width=paramToString_Param->Width;

  if(size<(Precision=paramToString_Param->Precision)){
    for(int i=size;i<Precision;i++){
      Buffer[i]='0';
    }
    size=Precision;
  }

  if((Attribute&vH_StringFormat_Attribute_LeftAlign)==0U){//右对齐
    char padding;
    int paddingLength;

    paddingLength=Width-size;

    padding=' ';
    if((Attribute&vH_StringFormat_Attribute_PaddingZero)!=0U){
      padding='0';
    }

    while(paddingLength>0){
      paddingLength--;
      Output(CharOutput,padding);
      r++;
    }
    
  }

  for(int i=0;i<size;i++){
    Output(CharOutput,Buffer[size-1-i]);
  }
  r+=size;

  while(r<Width){
    Output(CharOutput,' ');
    r++;
  }
  
  return r;
}

static Hsize ParamToString_Function_f(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params){
  Hsize r;

  Hbyte Attribute;

  Attribute=paramToString_Param->Attribute;

#if H_StringFormat_Support_Lf_Type!=H_StringFormat_Support_Lf_Type_None
  if((Attribute&vH_StringFormat_Attribute_Size_Mask)==vH_StringFormat_Attribute_Size_L){
    Hlongdouble val;
    
    val=va_arg(*Params,Hlongdouble);
    
    r=LongDoubleToOutput(CharOutput,paramToString_Param,val);
  }else
#endif
#if H_StringFormat_f_UseSinglePrecision
  if((Attribute&vH_StringFormat_Attribute_Size_Mask)==0U){
    double val;

    val=va_arg(*Params,double);

    r=FloatToOutput(CharOutput,paramToString_Param,(float)val);
  }else
#endif
  {
    double val;

    val=va_arg(*Params,double);

    r=DoubleToOutput(CharOutput,paramToString_Param,val);
  }
  return r;
}

static Hsize ParamToString_Function_eE(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params,char base){
  Hsize r;

  Hbyte Attribute;

  Attribute=paramToString_Param->Attribute;

#if H_StringFormat_Support_Lf_Type!=H_StringFormat_Support_Lf_Type_None
  if((Attribute&vH_StringFormat_Attribute_Size_Mask)==vH_StringFormat_Attribute_Size_L){
    Hlongdouble val;
    
    val=va_arg(*Params,Hlongdouble);
    
    r=LongDoubleToOutput_eE(CharOutput,paramToString_Param,val,base);
  }else
#endif
#if H_StringFormat_f_UseSinglePrecision
  if((Attribute&vH_StringFormat_Attribute_Size_Mask)==0U){
    double val;

    val=va_arg(*Params,double);

    r=FloatToOutput_eE(CharOutput,paramToString_Param,(float)val,base);
  }else
#endif
  {
    double val;

    val=va_arg(*Params,double);

    r=DoubleToOutput_eE(CharOutput,paramToString_Param,val,base);
  }
  return r;
}
static Hsize ParamToString_Function_e(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params){
  return ParamToString_Function_eE(CharOutput,paramToString_Param,Params,'e');
}
static Hsize ParamToString_Function_E(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params){
  return ParamToString_Function_eE(CharOutput,paramToString_Param,Params,'E');
}

static Hsize ParamToString_Function_gG(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params,char base){
  double val;

  val=va_arg(*Params,double);

  {
    int Precision;
    double addval;

    Precision=paramToString_Param->Precision;
    if(Precision<0){
      Precision=6;
    }

    addval=0.5;
    while(Precision>0){
      Precision--;
      addval*=0.1;
    }

    if(val<0.0){
      val-=addval;
    }else{
      val+=addval;
    }
  }

  if((val>=10000.0)||(val<=-10000.0)){
#if H_StringFormat_f_UseSinglePrecision
    return FloatToOutput_eE(CharOutput,paramToString_Param,(float)val,base-('g'-'e'));
#else
    return DoubleToOutput_eE(CharOutput,paramToString_Param,val,base-('g'-'e'));
#endif
  }

#if H_StringFormat_f_UseSinglePrecision
  return FloatToOutput(CharOutput,paramToString_Param,(float)val);
#else
  return DoubleToOutput(CharOutput,paramToString_Param,val);
#endif
}
static Hsize ParamToString_Function_g(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params){
  return ParamToString_Function_gG(CharOutput,paramToString_Param,Params,'g');
}
static Hsize ParamToString_Function_G(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params){
  return ParamToString_Function_gG(CharOutput,paramToString_Param,Params,'G');
}

static Hsize ParamToString_Function_o(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params){
  Huint64 val;
  int size;

  val=0;
  switch(paramToString_Param->Attribute&vH_StringFormat_Attribute_Size_Mask){
    case vH_StringFormat_Attribute_Size_h:
      size=sizeof(unsigned short int);
      val=va_arg(*Params,unsigned int);
      break;
    case vH_StringFormat_Attribute_Size_l:
      size=sizeof(unsigned long int);
      val=va_arg(*Params,unsigned long int);
      break;
    case vH_StringFormat_Attribute_Size_ll:
      size=sizeof(unsigned long int);
      val=va_arg(*Params,unsigned long long int);
      break;
    default:
      size=sizeof(int);
      val=va_arg(*Params,unsigned int);
      break;
  }

  return ParamToString_Function_Oct(CharOutput,paramToString_Param,val,size);
}


static Hsize ParamToString_Function_xX(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params,char base){
  Huint64 val;
  int size;

  val=0;
  switch(paramToString_Param->Attribute&vH_StringFormat_Attribute_Size_Mask){
    case vH_StringFormat_Attribute_Size_h:
      size=sizeof(unsigned short int);
      val=va_arg(*Params,unsigned int);
      break;
    case vH_StringFormat_Attribute_Size_l:
      size=sizeof(unsigned long int);
      val=va_arg(*Params,unsigned long int);
      break;
    case vH_StringFormat_Attribute_Size_ll:
      size=sizeof(unsigned long int);
      val=va_arg(*Params,unsigned long long int);
      break;
    default:
      size=sizeof(int);
      val=va_arg(*Params,unsigned int);
      break;
  }

  return ParamToString_Function_Hex(CharOutput,paramToString_Param,val,size,base);
}
static Hsize ParamToString_Function_x(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params){
  return ParamToString_Function_xX(CharOutput,paramToString_Param,Params,'x');
}
static Hsize ParamToString_Function_X(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params){
  return ParamToString_Function_xX(CharOutput,paramToString_Param,Params,'X');
}

static Hsize ParamToString_Function_aA(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params,char base){
  Hsize r;

#if H_StringFormat_Support_Lf_Type!=H_StringFormat_Support_Lf_Type_None
  if((paramToString_Param->Attribute&vH_StringFormat_Attribute_Size_Mask)==vH_StringFormat_Attribute_Size_L){
    Hlongdouble val;
    
    val=va_arg(*Params,Hlongdouble);
    
    r=ParamToString_Function_HexLongDouble(CharOutput,paramToString_Param,val,base+('x'-'a'));
  }else
#endif
  {
    double val;

    val=va_arg(*Params,double);

    r=ParamToString_Function_HexDouble(CharOutput,paramToString_Param,val,base+('x'-'a'));
  }
  return r;
}
static Hsize ParamToString_Function_a(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params){
  return ParamToString_Function_aA(CharOutput,paramToString_Param,Params,'a');
}
static Hsize ParamToString_Function_A(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params){
  return ParamToString_Function_aA(CharOutput,paramToString_Param,Params,'A');
}

static Hsize ParamToString_Function_p(H_StringFormat_CharOutput* CharOutput,const ParamToString_Param* paramToString_Param,va_list* Params){
  Huintptr val;
  ParamToString_Param paramToString_Param_loc;
  
  val=(Huintptr)va_arg(*Params,void*);

  paramToString_Param_loc=*paramToString_Param;
  paramToString_Param_loc.Precision=sizeof(void*)*2;
  paramToString_Param_loc.Attribute=0;

  return ParamToString_Function_Hex(CharOutput,&paramToString_Param_loc,(Huint64)val,sizeof(void*),'X');
}




Hsize H_StringFormat(H_StringFormat_CharOutput* CharOutput,const char* Format,va_list* Params){
  int c;
  Hsize r;
  H_StringFormat_CharOutput_Callback_t Output;

  Output=CharOutput->Output;

  r=0;
  while((c=*Format)!='\0'){
    ParamToString_Param paramToString_Param;
    Hbyte Type;
    Hbyte TypeIndex;

    Format++;

    if(c!='%'){
      Output(CharOutput,c);
      r++;
      continue;
    }

    paramToString_Param.Attribute=0x00U;
    paramToString_Param.Width=-1;
    paramToString_Param.Precision=-1;

    //attribute Flag
    while((c=*Format)!='\0'){
      if(c>128){
        break;
      }

      //判断Flag字符
      if((CharType[c]&vH_StringFormat_Type_FlagMask)!=0U){
        switch(c){
          case '0':
            paramToString_Param.Attribute|=vH_StringFormat_Attribute_PaddingZero;
            break;
          case '-':
            paramToString_Param.Attribute|=vH_StringFormat_Attribute_LeftAlign;
            break;
          case '+':
            paramToString_Param.Attribute|=vH_StringFormat_Attribute_Sign;
            break;
          case ' ':
            paramToString_Param.Attribute|=vH_StringFormat_Attribute_Space;
            break;
          case '#':
            paramToString_Param.Attribute|=vH_StringFormat_Attribute_Prefix;
            break;
          default:
            return r;
        }
        Format++;
      }else{
        break;
      }
    }

    if(c=='%'){
      Format++;
      
      Output(CharOutput,c);
      r++;
      continue;
    }

    //width
    while((c=*Format)!='\0'){
      if(c=='*'){
        paramToString_Param.Width=va_arg(*Params,int);
        Format++;
        break;
      }
      if((c<'0')||(c>'9')){
        break;
      }
      if(paramToString_Param.Width<0){
        paramToString_Param.Width=0;
      }
      paramToString_Param.Width=paramToString_Param.Width*10+c-'0';
      Format++;
    }

    //.precision 
    if((c=*Format)=='.'){
      Format++;

      while((c=*Format)!='\0'){
        if(c=='*'){
          paramToString_Param.Precision=va_arg(*Params,int);
          Format++;
          break;
        }
        if((c<'0')||(c>'9')){
          break;
        }
        if(paramToString_Param.Precision<0){
          paramToString_Param.Precision=0;
        }
        paramToString_Param.Precision=paramToString_Param.Precision*10+c-'0';
        Format++;
      }
    }

    //length
    while((c=*Format)!='\0'){
      if(c>128){
        break;
      }
      if((CharType[c]&vH_StringFormat_Type_LengthMask)==0x00U){
        break;
      }
      if(c=='l'){
        if((paramToString_Param.Attribute&vH_StringFormat_Attribute_Size_Mask)!=0U){
          paramToString_Param.Attribute=(paramToString_Param.Attribute&(~vH_StringFormat_Attribute_Size_Mask))|vH_StringFormat_Attribute_Size_ll;
        }else{
          paramToString_Param.Attribute|=vH_StringFormat_Attribute_Size_l;
        }
        Format++;
        c=*Format;
      }else if(c=='h'){
        paramToString_Param.Attribute|=vH_StringFormat_Attribute_Size_h;
        Format++;
        c=*Format;
        break;
      }else if(c=='L'){
        paramToString_Param.Attribute=(paramToString_Param.Attribute&(~vH_StringFormat_Attribute_Size_Mask))|vH_StringFormat_Attribute_Size_L;
        Format++;
        c=*Format;
        break;
      }else{
        break;
      }
    }

    //specifier
    {
      if(c>128){
        return r;
      }
      Type=CharType[c];
      TypeIndex=Type&vH_StringFormat_Type_Specifier_Mask;
      if((TypeIndex<vH_StringFormat_Type_Specifier_Min)||(TypeIndex>vH_StringFormat_Type_Specifier_Max)){
        return r;
      }
  
      if((Type&vH_StringFormat_Type_Uppercase)==0x00U){
        r+=ParamToString_FunctionList[TypeIndex](CharOutput,&paramToString_Param,Params);
      }else{
        r+=ParamToString_Uppercase_FunctionList[TypeIndex](CharOutput,&paramToString_Param,Params);
      }
    }

    Format++;
  }

  return r;
}



